Skip to content

Commit

Permalink
Add initialization tasks and procedure finding
Browse files Browse the repository at this point in the history
functions
  • Loading branch information
WMXPY committed Nov 3, 2023
1 parent a54a898 commit 8baed0a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @author WMXPY
* @namespace Orchestration_Initialize
* @description Initialize Tasks
* @description Create Tasks
*/

import { Optional } from "@sudoo/optional";
Expand Down
32 changes: 32 additions & 0 deletions src/orchestration/initialize/recursive-add-task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @author WMXPY
* @namespace Orchestration_Initialize
* @description Recursive Add Task
*/

import { PubProcedureConfiguration } from "../../procedure/definition/configuration";
import { PubTask } from "../../task/task";
import { PubCachedWorkflowConfiguration } from "../../workflow/cache/configuration";
import { findNextProcedures } from "../procedure/find-next-procedure";

export const initializeRecursiveAddTask = (
configuration: PubCachedWorkflowConfiguration,
currentProcedure: PubProcedureConfiguration,
tasks: PubTask[],
): PubTask[] => {

const nextProcedures: PubProcedureConfiguration[] = findNextProcedures(
currentProcedure,
configuration,
);

const nextTasks: PubTask[] = nextProcedures.map((procedure: PubProcedureConfiguration) => {

return PubTask.fromIdentifier(procedure.identifier);
});

return [
...tasks,
...nextTasks,
];
};
38 changes: 38 additions & 0 deletions src/orchestration/procedure/find-next-procedure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @author WMXPY
* @namespace Orchestration_Procedure
* @description Find Next Procedure
*/

import { PUB_CONNECTION_WAYPOINT_TYPE } from "../../connection/definition/configuration";
import { PubProcedureConfiguration } from "../../procedure/definition/configuration";
import { PubCachedWorkflowConfiguration } from "../../workflow/cache/configuration";

export const findNextProcedures = (
currentProcedure: PubProcedureConfiguration,
configuration: PubCachedWorkflowConfiguration,
): PubProcedureConfiguration[] => {

const triggerConnections = configuration.configuration.connections
.filter((connection) => {

return connection.triggerProcedureIdentifier ===
currentProcedure.identifier
&& connection.triggerProcedureWaypointType ===
PUB_CONNECTION_WAYPOINT_TYPE.PROCEDURE_SELF_END;
});

const nextProcedures: PubProcedureConfiguration[] = triggerConnections
.filter((connection) => {
return connection.nextProcedureWaypointType ===
PUB_CONNECTION_WAYPOINT_TYPE.PROCEDURE_SELF_START;
})
.map((connection) => {
return configuration.getProcedureByIdentifier(connection.nextProcedureIdentifier);
})
.filter((procedure): procedure is PubProcedureConfiguration => {
return Boolean(procedure);
});

return nextProcedures;
};
2 changes: 1 addition & 1 deletion src/procedure/definition/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum PUB_PROCEDURE_TYPE {
MAP = "MAP",
}

export type PubProcedureConfiguration<T extends PUB_PROCEDURE_TYPE> = {
export type PubProcedureConfiguration<T extends PUB_PROCEDURE_TYPE = PUB_PROCEDURE_TYPE> = {

readonly identifier: string;
readonly type: T;
Expand Down

0 comments on commit 8baed0a

Please sign in to comment.