2023-02-16 22:16:24 +00:00
|
|
|
import Express, {
|
|
|
|
ExpressRequest,
|
|
|
|
ExpressResponse,
|
|
|
|
ExpressRouter,
|
|
|
|
} from 'CommonServer/Utils/Express';
|
|
|
|
import Response from 'CommonServer/Utils/Response';
|
2023-02-16 22:45:22 +00:00
|
|
|
import ObjectID from 'Common/Types/ObjectID';
|
2023-02-16 22:16:24 +00:00
|
|
|
import BadDataException from 'Common/Types/Exception/BadDataException';
|
|
|
|
import QueueWorkflow from '../Services/QueueWorkflow';
|
|
|
|
|
2023-02-16 22:45:22 +00:00
|
|
|
export default class ManualAPI {
|
2023-02-16 22:16:24 +00:00
|
|
|
public router!: ExpressRouter;
|
|
|
|
|
|
|
|
public constructor() {
|
|
|
|
this.router = Express.getRouter();
|
|
|
|
|
2023-02-16 22:45:22 +00:00
|
|
|
this.router.get(`/run/:workflowId`, this.manuallyRunWorkflow);
|
2023-02-16 22:16:24 +00:00
|
|
|
|
2023-02-16 22:45:22 +00:00
|
|
|
this.router.post(`/run/:workflowId`, this.manuallyRunWorkflow);
|
2023-02-16 22:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async manuallyRunWorkflow(
|
|
|
|
req: ExpressRequest,
|
2023-02-16 22:45:22 +00:00
|
|
|
res: ExpressResponse
|
2023-02-16 23:02:42 +00:00
|
|
|
): Promise<void> {
|
2023-02-16 22:16:24 +00:00
|
|
|
// add this workflow to the run queue and return the 200 response.
|
|
|
|
|
2023-02-16 22:45:22 +00:00
|
|
|
if (!req.params['workflowId']) {
|
|
|
|
return Response.sendErrorResponse(
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
new BadDataException('workflowId not found in URL')
|
|
|
|
);
|
2023-02-16 22:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await QueueWorkflow.addWorkflowToQueue({
|
|
|
|
workflowId: new ObjectID(req.params['workflowId'] as string),
|
2023-02-17 16:00:02 +00:00
|
|
|
returnValues: req.body.data || {},
|
2023-02-16 22:45:22 +00:00
|
|
|
});
|
2023-02-16 22:16:24 +00:00
|
|
|
|
2023-02-16 22:45:22 +00:00
|
|
|
return Response.sendJsonObjectResponse(req, res, {
|
|
|
|
status: 'Scheduled',
|
|
|
|
});
|
2023-02-16 22:16:24 +00:00
|
|
|
}
|
|
|
|
}
|