mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import QueueWorkflow from "../Services/QueueWorkflow";
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
import ObjectID from "Common/Types/ObjectID";
|
|
import Express, {
|
|
ExpressRequest,
|
|
ExpressResponse,
|
|
ExpressRouter,
|
|
} from "Common/Server/Utils/Express";
|
|
import Response from "Common/Server/Utils/Response";
|
|
|
|
export default class ManualAPI {
|
|
public router!: ExpressRouter;
|
|
|
|
public constructor() {
|
|
this.router = Express.getRouter();
|
|
|
|
this.router.get(`/run/:workflowId`, this.manuallyRunWorkflow);
|
|
|
|
this.router.post(`/run/:workflowId`, this.manuallyRunWorkflow);
|
|
}
|
|
|
|
public async manuallyRunWorkflow(
|
|
req: ExpressRequest,
|
|
res: ExpressResponse,
|
|
): Promise<void> {
|
|
// add this workflow to the run queue and return the 200 response.
|
|
|
|
if (!req.params["workflowId"]) {
|
|
return Response.sendErrorResponse(
|
|
req,
|
|
res,
|
|
new BadDataException("workflowId not found in URL"),
|
|
);
|
|
}
|
|
|
|
await QueueWorkflow.addWorkflowToQueue({
|
|
workflowId: new ObjectID(req.params["workflowId"] as string),
|
|
returnValues: req.body.data || {},
|
|
});
|
|
|
|
return Response.sendJsonObjectResponse(req, res, {
|
|
status: "Scheduled",
|
|
});
|
|
}
|
|
}
|