Skip to content

Commit cbc2db3

Browse files
committed
Fix automation next poll scheduling for locked steps
1 parent 87421ec commit cbc2db3

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

ghost/core/core/server/services/automations/fake-database-automations-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function fetchAndLockSteps(database: DatabaseSync, limit: number): {
303303
if (candidates.length === 0) {
304304
return {
305305
steps: [],
306-
nextStepReadyAt: findNextPendingReadyAt(database, now)
306+
nextStepReadyAt: findNextPendingReadyAt(database, staleLockCutoff)
307307
};
308308
}
309309

ghost/core/test/unit/server/services/automations/automations-repository.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,24 @@ describe('automations repository', function () {
556556
assert.equal(result.nextStepReadyAt.toISOString(), sooner.toISOString());
557557
});
558558

559+
it('does not schedule an immediate poll when due steps are locked by another worker', async function () {
560+
const automation = await getAutomationBySlug('member-welcome-email-free');
561+
const action = getActionByIndex(automation.id, 0);
562+
const run = insertRun(automation.id);
563+
const lockedAt = new Date(Date.now() - 60 * 1000);
564+
565+
insertStep(run.id, action.revision_id, {
566+
locked_at: lockedAt.toISOString(),
567+
ready_at: new Date(Date.now() - 1000).toISOString(),
568+
locked_by: 'fresh-lock'
569+
});
570+
571+
const result = await repo.fetchAndLockSteps(10);
572+
573+
assert.deepEqual(result.steps, []);
574+
assert.equal(result.nextStepReadyAt, null);
575+
});
576+
559577
it('respects the limit argument', async function () {
560578
const automation = await getAutomationBySlug('member-welcome-email-free');
561579
const action = getActionByIndex(automation.id, 0);

0 commit comments

Comments
 (0)