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") {
|
if (job.name === "daily-s3-sync") {
|
||||||
await this.performDailySync();
|
await this.performDailySync();
|
||||||
} else if (job.name === "daily-analytics") {
|
} 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();
|
await this.triggerJobAnalysis();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -114,7 +121,7 @@ export class DailyS3Scheduler {
|
|||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
repeat: {
|
repeat: {
|
||||||
pattern: "21 * * * *", //9PM
|
pattern: "0 21 * * *", //9PM
|
||||||
tz: "America/Los_Angeles"
|
tz: "America/Los_Angeles"
|
||||||
},
|
},
|
||||||
jobId: "daily-analytics"
|
jobId: "daily-analytics"
|
||||||
@@ -209,7 +216,7 @@ export class DailyS3Scheduler {
|
|||||||
logger.info("Triggering jobs directory analysis...");
|
logger.info("Triggering jobs directory analysis...");
|
||||||
try {
|
try {
|
||||||
const analysis = await analyzeJobsDirectory();
|
const analysis = await analyzeJobsDirectory();
|
||||||
logger.info("Jobs directory analysis completed:", analysis);
|
logger.info("Jobs directory analysis completed");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Jobs directory analysis failed:", error);
|
logger.error("Jobs directory analysis failed:", error);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user