2024-06-14 11:09:53 +00:00
|
|
|
import ComponentCodeAPI from "./API/ComponentCode";
|
|
|
|
import ManualAPI from "./API/Manual";
|
|
|
|
import WorkflowAPI from "./API/Workflow";
|
|
|
|
import RunWorkflow from "./Services/RunWorkflow";
|
|
|
|
import { JSONObject } from "Common/Types/JSON";
|
|
|
|
import ObjectID from "Common/Types/ObjectID";
|
2024-08-07 21:50:32 +00:00
|
|
|
import { QueueJob, QueueName } from "Common/Server/Infrastructure/Queue";
|
|
|
|
import QueueWorker from "Common/Server/Infrastructure/QueueWorker";
|
|
|
|
import FeatureSet from "Common/Server/Types/FeatureSet";
|
2024-01-11 13:46:11 +00:00
|
|
|
import Express, {
|
2024-06-14 11:09:53 +00:00
|
|
|
ExpressApplication,
|
|
|
|
ExpressRequest,
|
|
|
|
ExpressResponse,
|
2024-08-07 21:50:32 +00:00
|
|
|
} from "Common/Server/Utils/Express";
|
|
|
|
import logger from "Common/Server/Utils/Logger";
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-09-18 11:09:29 +00:00
|
|
|
const APP_NAME: string = "workflow";
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-04-24 12:03:07 +00:00
|
|
|
const WorkflowFeatureSet: FeatureSet = {
|
2024-06-14 11:09:53 +00:00
|
|
|
init: async (): Promise<void> => {
|
|
|
|
try {
|
|
|
|
const app: ExpressApplication = Express.getExpressApp();
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
app.use(`/${APP_NAME}/manual`, new ManualAPI().router);
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
app.use(`/${APP_NAME}`, new WorkflowAPI().router);
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
app.get(
|
|
|
|
`/${APP_NAME}/docs/:componentName`,
|
|
|
|
(req: ExpressRequest, res: ExpressResponse) => {
|
|
|
|
res.sendFile(
|
2024-09-16 22:22:15 +00:00
|
|
|
"/usr/src/app/Docs/ComponentDocumentation/" +
|
2024-06-14 11:09:53 +00:00
|
|
|
req.params["componentName"],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const componentCodeAPI: ComponentCodeAPI = new ComponentCodeAPI();
|
|
|
|
componentCodeAPI.init();
|
2024-04-24 18:17:38 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
app.use(`/${APP_NAME}`, componentCodeAPI.router);
|
2024-01-11 13:46:11 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
// Job process.
|
|
|
|
QueueWorker.getWorker(
|
|
|
|
QueueName.Workflow,
|
|
|
|
async (job: QueueJob) => {
|
|
|
|
await new RunWorkflow().runWorkflow({
|
|
|
|
workflowId: new ObjectID(job.data["workflowId"] as string),
|
|
|
|
workflowLogId: job.data["workflowLogId"]
|
|
|
|
? new ObjectID(job.data["workflowLogId"] as string)
|
|
|
|
: null,
|
|
|
|
arguments: job.data.data as JSONObject,
|
|
|
|
timeout: 5000,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
{ concurrency: 10 },
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error("App Init Failed:");
|
|
|
|
logger.error(err);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
},
|
2024-01-11 13:55:07 +00:00
|
|
|
};
|
2024-01-11 13:46:11 +00:00
|
|
|
|
|
|
|
export default WorkflowFeatureSet;
|