chore: register schedule worker
This commit is contained in:
@@ -13,7 +13,7 @@ if (!process.env.DB_USER || !process.env.DB_PASSWORD || !process.env.DB_HOST ||
|
|||||||
|
|
||||||
const pgBossConnectionString = `postgresql://${process.env.DB_USER}:${encodeURIComponent(process.env.DB_PASSWORD)}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`;
|
const pgBossConnectionString = `postgresql://${process.env.DB_USER}:${encodeURIComponent(process.env.DB_PASSWORD)}@${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`;
|
||||||
|
|
||||||
const pgBoss = new PgBoss({
|
export const pgBoss = new PgBoss({
|
||||||
connectionString: pgBossConnectionString,
|
connectionString: pgBossConnectionString,
|
||||||
max: 3,
|
max: 3,
|
||||||
expireInHours: 23,
|
expireInHours: 23,
|
||||||
@@ -87,8 +87,9 @@ async function registerScheduledWorkflowWorker() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a worker for a specific queue
|
* Register a worker for a specific queue
|
||||||
|
* Exported to allow dynamic registration when new schedules are created
|
||||||
*/
|
*/
|
||||||
async function registerWorkerForQueue(queueName: string) {
|
export async function registerWorkerForQueue(queueName: string) {
|
||||||
try {
|
try {
|
||||||
if (registeredQueues.has(queueName)) {
|
if (registeredQueues.has(queueName)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import { pgBossClient } from './pgboss';
|
import { pgBossClient } from './pgboss';
|
||||||
|
import { registerWorkerForQueue } from '../schedule-worker';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to schedule a cron job using PgBoss
|
* Utility function to schedule a cron job using PgBoss
|
||||||
@@ -28,6 +29,8 @@ export async function scheduleWorkflow(id: string, userId: string, cronExpressi
|
|||||||
{ tz: timezone }
|
{ tz: timezone }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await registerWorkerForQueue(queueName);
|
||||||
|
|
||||||
logger.log('info', `Scheduled workflow job for robot ${id}`);
|
logger.log('info', `Scheduled workflow job for robot ${id}`);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user