Skip to content

Commit c420230

Browse files
committed
feat(scraper): Added SCRAPE_ON_START flag
To start scraping on boot
1 parent 3037391 commit c420230

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ TRAKT_KEY=
3939

4040
# The time between cronjobs.
4141
CRON_TIME='0 0 3 * * *'
42+
43+
# Should the scraper start scraping on start
44+
SCRAPE_ON_START=false

apps/scraper/src/scraper.module.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ export class ScraperModule implements OnApplicationBootstrap {
5151
private providersService: ProvidersService
5252

5353
public onApplicationBootstrap(): void {
54-
const job = new CronJob(this.configService.get('CRON_TIME'), () => {
54+
const job = new CronJob(this.configService.get(ConfigService.CRON_TIME), () => {
5555
this.scrapeConfigs()
5656
})
5757

5858
this.schedulerRegistry.addCronJob(ScraperModule.JOB_NAME, job)
5959
job.start()
6060

61-
this.logger.log(`Enabled cron on '${this.configService.get('CRON_TIME')}'`)
61+
this.logger.log(`Enabled cron on '${this.configService.get(ConfigService.CRON_TIME)}'`)
62+
63+
if (this.configService.get(ConfigService.SCRAPE_ON_START)) {
64+
this.scrapeConfigs()
65+
}
6266
}
6367

6468
private async scrapeConfigs(): Promise<void> {

apps/scraper/src/shared/config/config.service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class ConfigService {
1515
public static readonly MONGO_PORT: string = 'MONGO_PORT'
1616
public static readonly MONGO_DATABASE: string = 'MONGO_DATABASE'
1717
public static readonly CRON_TIME: string = 'CRON_TIME'
18+
public static readonly SCRAPE_ON_START: string = 'SCRAPE_ON_START'
1819
public static readonly TRAKT_KEY: string = 'TRAKT_KEY'
1920
public static readonly TMDB_KEY: string = 'TMDB_KEY'
2021
public static readonly TVDB_KEY: string = 'TVDB_KEY'
@@ -109,6 +110,8 @@ export class ConfigService {
109110

110111
[ConfigService.FANART_KEY]: Joi.string()
111112
.required(),
113+
114+
[ConfigService.SCRAPE_ON_START]: Joi.boolean()
112115
})
113116

114117
const { error, value: validatedEnvConfig } = envVarsSchema.validate(envConfig, { stripUnknown: true })

0 commit comments

Comments
 (0)