diff --git a/server/src/api/sdk.ts b/server/src/api/sdk.ts index 76e63d31..1d775a0c 100644 --- a/server/src/api/sdk.ts +++ b/server/src/api/sdk.ts @@ -300,7 +300,7 @@ router.put("/sdk/robots/:id", requireAPIKey, async (req: AuthenticatedRequest, r } try { - await scheduleWorkflow(robotId, cronExpression, timezone); + await scheduleWorkflow(robotId, req.user.id, cronExpression, timezone); } catch (scheduleError: any) { logger.error(`[SDK] Failed to schedule workflow for robot ${robotId}: ${scheduleError.message}`); return res.status(500).json({ diff --git a/server/src/routes/storage.ts b/server/src/routes/storage.ts index 65476360..7d50b780 100644 --- a/server/src/routes/storage.ts +++ b/server/src/routes/storage.ts @@ -894,7 +894,7 @@ router.put('/schedule/:id/', requireSignIn, async (req: AuthenticatedRequest, re logger.log('warn', `Failed to cancel existing schedule for robot ${id}: ${cancelError}`); } - await scheduleWorkflow(id, cronExpression, timezone); + await scheduleWorkflow(id, req.user.id, cronExpression, timezone); const nextRunAt = computeNextRun(cronExpression, timezone); diff --git a/server/src/storage/schedule.ts b/server/src/storage/schedule.ts index 3e149a47..16cfb3f0 100644 --- a/server/src/storage/schedule.ts +++ b/server/src/storage/schedule.ts @@ -5,6 +5,7 @@ import { v4 as uuid } from 'uuid'; import logger from '../logger'; import { pgBossClient } from './pgboss'; +import { registerWorkerForQueue } from '../schedule-worker'; /** * Utility function to schedule a cron job using PgBoss @@ -13,7 +14,7 @@ import { pgBossClient } from './pgboss'; * @param cronExpression The cron expression for scheduling * @param timezone The timezone for the cron expression */ -export async function scheduleWorkflow(id: string, cronExpression: string, timezone: string): Promise { +export async function scheduleWorkflow(id: string, userId: string, cronExpression: string, timezone: string): Promise { try { const runId = uuid(); @@ -24,7 +25,7 @@ export async function scheduleWorkflow(id: string, cronExpression: string, timez await pgBossClient.createQueue(queueName); await pgBossClient.schedule(queueName, cronExpression, - { id, runId }, + { id, runId, userId }, { tz: timezone } );