Skip to content

Commit dea7273

Browse files
authored
Cleanups to automation poll enqueueing (#29025)
ref 8c72afd This change should have no user impact. 1. Update the comment about deadlocking for accuracy. 2. `await` the flushing of the event loop instead of returning immediately, for consistency with the `await` elsewhere in the function.
1 parent 0b1596d commit dea7273

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • ghost/core/core/server/services/automations

ghost/core/core/server/services/automations/service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type DomainEvents from '@tryghost/domain-events';
44
import {oneAtATime} from '../../../shared/one-at-a-time';
55
import {poll} from './poll';
66
import * as automationsApi from './automations-api';
7+
import {setImmediate as flushEventLoop} from 'node:timers/promises';
78

89
const urlUtils = require('../../../shared/url-utils');
910
const logging = require('@tryghost/logging');
@@ -44,10 +45,10 @@ export class AutomationsService {
4445
const enqueuePollAt = async (date: Readonly<Date>): Promise<void> => {
4546
const isRequestedDateInTheFuture = new Date() < date;
4647
if (!isRequestedDateInTheFuture) {
47-
// Dispatch a task instead of calling immediately to resolve issues with better-sqlite3
48-
// being synchronous and blocking the schedulerAdapter.schedule call below, which can
49-
// cause a deadlock in some cases.
50-
setImmediate(() => enqueuePollNow());
48+
// If you're using synchronous SQLite, we want to finish unwinding the call stack
49+
// before dispatching another poll event.
50+
await flushEventLoop();
51+
enqueuePollNow();
5152
return;
5253
}
5354

0 commit comments

Comments
 (0)