feat: post endpoint to schedule workflow

This commit is contained in:
karishmas6
2024-09-11 12:53:28 +05:30
parent 9cbd218d00
commit 2f681deb3f

View File

@@ -10,6 +10,7 @@ import { chromium } from "playwright";
import { browserPool } from "../server";
import fs from "fs";
import { uuid } from "uuidv4";
import { workflowQueue } from '../workflow-management/scheduler';
export const router = Router();
@@ -188,6 +189,27 @@ router.post('/runs/run/:fileName/:runId', async (req, res) => {
}
});
router.post('/schedule/:fileName/:runId', async (req, res) => {
try {
const { fileName, runId } = req.params;
const { scheduleTime } = req.body;
if (!fileName || !runId || !scheduleTime) {
return res.status(400).json({ error: 'Missing required parameters' });
}
const delay = new Date(scheduleTime).getTime() - Date.now();
// Add job to the queue with delay
await workflowQueue.add('run workflow', { fileName, runId }, { delay: Math.max(0, delay) });
res.status(200).json({ message: 'Workflow scheduled successfully' });
} catch (error) {
console.error('Error scheduling workflow:', error);
res.status(500).json({ error: 'Failed to schedule workflow' });
}
});
/**
* POST endpoint for aborting a current interpretation of the run.
*/