Add 90 min random jitter to prevent API overload.
This commit is contained in:
@@ -65,6 +65,13 @@ export class DailyS3Scheduler {
|
||||
if (job.name === "daily-s3-sync") {
|
||||
await this.performDailySync();
|
||||
} else if (job.name === "daily-analytics") {
|
||||
// Add random delay of 0-90 minutes to prevent API flooding
|
||||
const randomDelayMinutes = Math.floor(Math.random() * 91); // 0-90 minutes
|
||||
const randomDelayMs = randomDelayMinutes * 60 * 1000;
|
||||
|
||||
logger.info(`[Scheduler] Analytics job will execute in ${randomDelayMinutes} minutes (${new Date(Date.now() + randomDelayMs).toISOString()})`);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, randomDelayMs));
|
||||
await this.triggerJobAnalysis();
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -114,7 +121,7 @@ export class DailyS3Scheduler {
|
||||
{},
|
||||
{
|
||||
repeat: {
|
||||
pattern: "21 * * * *", //9PM
|
||||
pattern: "0 21 * * *", //9PM
|
||||
tz: "America/Los_Angeles"
|
||||
},
|
||||
jobId: "daily-analytics"
|
||||
@@ -209,7 +216,7 @@ export class DailyS3Scheduler {
|
||||
logger.info("Triggering jobs directory analysis...");
|
||||
try {
|
||||
const analysis = await analyzeJobsDirectory();
|
||||
logger.info("Jobs directory analysis completed:", analysis);
|
||||
logger.info("Jobs directory analysis completed");
|
||||
} catch (error) {
|
||||
logger.error("Jobs directory analysis failed:", error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user