Skip to content

Commit

Permalink
restart runner?
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbuechele committed Sep 14, 2024
1 parent 846a995 commit 1c00077
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,33 @@ const taskList = {
nonceRequestInvalidate,
};

export default async function () {
const runnerOptions: RunnerOptions = {
connectionString: env.DIRECT_URL,
concurrency: 1,
taskList: taskList as any,
events,
crontab: [
'*/5 * * * * nuclinoUpdateMessage ?max=1&jobKey=nuclinoUpdateMessage&jobKeyMode=replace',
`0 0 * * * gmailSubscription ?id=booking&fill=1d&max=3 {"account":"booking@kulturspektakel.de"}`,
`0 0 * * * gmailSubscription ?id=info&fill=1d&max=3 {"account":"info@kulturspektakel.de"}`,
`0 0 * * * gmailSubscription ?id=lager&fill=1d&max=3 {"account":"lager@kulturspektakel.de"}`,
].join('\n'),
};
const runnerOptions: RunnerOptions = {
connectionString: env.DIRECT_URL,
concurrency: 1,
taskList: taskList as any,
events,
crontab: [
'*/5 * * * * nuclinoUpdateMessage ?max=1&jobKey=nuclinoUpdateMessage&jobKeyMode=replace',
`0 0 * * * gmailSubscription ?id=booking&fill=1d&max=3 {"account":"booking@kulturspektakel.de"}`,
`0 0 * * * gmailSubscription ?id=info&fill=1d&max=3 {"account":"info@kulturspektakel.de"}`,
`0 0 * * * gmailSubscription ?id=lager&fill=1d&max=3 {"account":"lager@kulturspektakel.de"}`,
].join('\n'),
};

const runner = await run(runnerOptions);
runner.promise.finally(async () => {
console.log('runner_error: restarting');
try {
await runner.stop();
} catch (e) {}
await sleep(5000);
await run(runnerOptions);
});
let runner: Runner | null = null;

export async function restart() {
console.log('runner_error: restarting');
try {
await runner?.stop();
} catch (e) {}
await sleep(5000);
await run(runnerOptions);
}

export default async function () {
runner = await run(runnerOptions);
runner.promise.finally(restart);
}

type Payload<T extends keyof typeof taskList> = Parameters<
Expand Down
3 changes: 3 additions & 0 deletions src/tasks/taskEvents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {EventEmitter} from 'events';
import {WorkerEvents} from 'graphile-worker';
import * as Sentry from '@sentry/node';
import {restart} from '.';

const emitter: WorkerEvents = new EventEmitter();

Expand All @@ -13,6 +14,8 @@ emitter.addListener('job:error', ({error, job, worker}) => {
});
});

emitter.addListener('worker:fatalError', restart);

[
'pool:listen:error' as const,
'pool:listen:release' as const,
Expand Down

0 comments on commit 1c00077

Please sign in to comment.