diff --git a/config.json b/config.json index 2984308a115be5b06c643a6b4cb842772fc4cfcd..be2d5bd472ac148867bdcbd45401e3b688cea88e 100644 --- a/config.json +++ b/config.json @@ -9,8 +9,7 @@ "name": "Enedis", "type": "ELECTRICITY", "oauth": true, - "slug": "enedisgrandlyon", - "cron": "0 30 6 * * *" + "slug": "enedisgrandlyon" }, "siteLink": "https://mon-compte-client.enedis.fr/" }, @@ -23,8 +22,7 @@ "name": "Eau du Grand Lyon", "type": "WATER", "oauth": false, - "slug": "eglgrandlyon", - "cron": "0 30 6 * * *" + "slug": "eglgrandlyon" }, "siteLink": "https://agence.eaudugrandlyon.com/inscription.aspx" }, @@ -37,8 +35,7 @@ "name": "GRDF", "type": "GAS", "oauth": false, - "slug": "grdfgrandlyon", - "cron": "0 30 6 * * *" + "slug": "grdfgrandlyon" }, "siteLink": "https://monespace.grdf.fr/monespace/connexion" } diff --git a/src/services/fluidConfigService.ts b/src/services/fluidConfigService.ts index 8f132a17eda43e43d8f4eeb1390841464c3ef29e..96d72f5ef0b92a3eb43b8a497615c3eab1ae5ea3 100644 --- a/src/services/fluidConfigService.ts +++ b/src/services/fluidConfigService.ts @@ -12,12 +12,14 @@ export default class FluidConfig { return this._fluidConfig } - public getCronArgs(slug: string): string { - const filtered = this._fluidConfig.filter( - fluidConfig => fluidConfig.konnectorConfig.slug === slug - ) - return filtered.length > 0 && filtered[0].konnectorConfig.cron - ? filtered[0].konnectorConfig.cron - : '0 30 8 * * *' + /** + * + * @param min Minimum hour for cron + * @param max Maximum hour for cron + */ + public getCronArgs(min = 8, max = 9): string { + const randomHour = Math.floor(Math.random() * (max - min + 1) + min) + const randomMinutes = Math.floor(Math.random() * 59) + return `0 ${randomMinutes} ${randomHour} * * *` } } diff --git a/src/services/triggersService.ts b/src/services/triggersService.ts index 6115785efeeea8fdaddfd4ff9d0d4778dbf75656..13a496e19a129a81ae4cdbb389bdb94bbe7cd0ed 100644 --- a/src/services/triggersService.ts +++ b/src/services/triggersService.ts @@ -48,7 +48,7 @@ export class TriggerService { ) } const fluidConfigService = new FluidConfig() - const cronArgs = fluidConfigService.getCronArgs(this._konnector.slug) + const cronArgs = fluidConfigService.getCronArgs() const triggerAttributes: TriggerAttributes = { type: '@cron', arguments: cronArgs,