Skip to content

Commit ae89883

Browse files
committed
Adhoc tasks run immediately. Make it explicit.
1 parent f3d3e0a commit ae89883

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

x-pack/platform/plugins/shared/task_manager/server/task_scheduling.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,8 @@ describe('TaskScheduling', () => {
13371337
schedule: undefined,
13381338
traceparent: 'parent',
13391339
enabled: true,
1340+
runAt: new Date(),
1341+
scheduledAt: new Date(),
13401342
},
13411343
],
13421344
undefined
@@ -1366,6 +1368,8 @@ describe('TaskScheduling', () => {
13661368
schedule: undefined,
13671369
traceparent: 'parent',
13681370
enabled: true,
1371+
runAt: new Date(),
1372+
scheduledAt: new Date(),
13691373
},
13701374
{
13711375
...task2,
@@ -1410,6 +1414,8 @@ describe('TaskScheduling', () => {
14101414
id: undefined,
14111415
traceparent: 'parent',
14121416
enabled: true,
1417+
runAt: new Date(),
1418+
scheduledAt: new Date(),
14131419
});
14141420

14151421
expect(omit(bulkSchedulePayload[1], 'runAt', 'scheduledAt')).toEqual({
@@ -1436,7 +1442,7 @@ describe('TaskScheduling', () => {
14361442
expect(t2RunAt).toBeLessThanOrEqual(5 * 60 * 1000);
14371443
});
14381444

1439-
test('does not jitter ad-hoc tasks at i > 0', async () => {
1445+
test('runs ad-hoc tasks immediately without jitter, even at i > 0', async () => {
14401446
const taskScheduling = new TaskScheduling(taskSchedulingOpts);
14411447
const recurringTask = {
14421448
taskType: 'foo',
@@ -1459,13 +1465,17 @@ describe('TaskScheduling', () => {
14591465
id: undefined,
14601466
traceparent: 'parent',
14611467
enabled: true,
1468+
runAt: new Date(),
1469+
scheduledAt: new Date(),
14621470
},
14631471
{
14641472
...adHocTask,
14651473
id: undefined,
14661474
schedule: undefined,
14671475
traceparent: 'parent',
14681476
enabled: true,
1477+
runAt: new Date(),
1478+
scheduledAt: new Date(),
14691479
},
14701480
]);
14711481
});

x-pack/platform/plugins/shared/task_manager/server/task_scheduling.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ export class TaskScheduling {
385385
}
386386

387387
const addJitter = (interval?: string): { runAt: Date; scheduledAt: Date } | undefined => {
388-
// Adhoc tasks run immediately, no explicit date means they are set to run now inside the store.
389-
if (!interval) return undefined;
388+
// Adhoc tasks run immediately.
389+
if (!interval) return { runAt: new Date(), scheduledAt: new Date() };
390390

391391
const now = Date.now();
392392
const maximumOffsetTimestamp = now + 1000 * 60 * 5; // now + 5 minutes

0 commit comments

Comments
 (0)