Skip to content

Commit

Permalink
implment own interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfagun74 committed Oct 26, 2024
1 parent eff95f0 commit 263242b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/modules/games/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Readable } from "stream";
import { Throttle } from "stream-throttle";
import unidecode from "unidecode";

import { Cron } from "@nestjs/schedule";
import { watch } from "chokidar";
import configuration from "../../configuration";
import globals from "../../globals";
Expand Down Expand Up @@ -46,19 +47,17 @@ export class FilesService implements OnApplicationBootstrap {
) {}

onApplicationBootstrap() {
if (configuration.TESTING.MOCK_FILES) return;

const indexIntervalInMinutes =
configuration.GAMES.INDEX_INTERVAL_IN_MINUTES;
const interval =
indexIntervalInMinutes > 0 ? indexIntervalInMinutes * 60 * 1000 : 0;
if (configuration.TESTING.MOCK_FILES) {
this.logger.warn({
message: "Skipping File Indexer.",
reason: "TESTING_MOCK_FILES is set to true.",
});
return;
}

watch(configuration.VOLUMES.FILES, {
depth: configuration.GAMES.SEARCH_RECURSIVE ? undefined : 0,
ignorePermissionErrors: true,
usePolling: interval > 0,
interval,
binaryInterval: interval,
ignoreInitial: true,
alwaysStat: true,
awaitWriteFinish: true,
Expand All @@ -72,6 +71,14 @@ export class FilesService implements OnApplicationBootstrap {
this.indexAllFiles();
}

@Cron(
`*/${configuration.GAMES.INDEX_INTERVAL_IN_MINUTES > 0 ? configuration.GAMES.INDEX_INTERVAL_IN_MINUTES : 1} * * * *`,
{
disabled:
configuration.GAMES.INDEX_INTERVAL_IN_MINUTES <= 0 ||
configuration.TESTING.MOCK_FILES,
},
)
public async indexAllFiles() {
for (const file of await this.readAllFiles())
this.index(file.path, { size: Number(file.size) } as Stats);
Expand Down

0 comments on commit 263242b

Please sign in to comment.