Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface EventTaskDef extends CommonTaskDef {
type: TaskType.EVENT;
sink: string;
asyncComplete?: boolean;
optional?: boolean;
Comment thread
DmitryBorisov-sm marked this conversation as resolved.
}

export interface ForkJoinTaskDef extends CommonTaskDef {
Expand Down Expand Up @@ -120,6 +121,7 @@ export interface HttpTaskDef extends CommonTaskDef {
};
type: TaskType.HTTP;
asyncComplete?: boolean;
optional?: boolean;
}

export interface InlineTaskInputParameters {
Expand All @@ -131,6 +133,7 @@ export interface InlineTaskInputParameters {
export interface InlineTaskDef extends CommonTaskDef {
type: TaskType.INLINE;
inputParameters: InlineTaskInputParameters;
optional?: boolean;
}

interface ContainingQueryExpression {
Expand All @@ -141,6 +144,7 @@ interface ContainingQueryExpression {
export interface JsonJQTransformTaskDef extends CommonTaskDef {
type: TaskType.JSON_JQ_TRANSFORM;
inputParameters: ContainingQueryExpression;
optional?: boolean;
}

export interface KafkaPublishInputParameters {
Expand All @@ -157,16 +161,19 @@ export interface KafkaPublishTaskDef extends CommonTaskDef {
kafka_request: KafkaPublishInputParameters;
};
type: TaskType.KAFKA_PUBLISH;
optional?: boolean;
}

export interface SetVariableTaskDef extends CommonTaskDef {
type: TaskType.SET_VARIABLE;
inputParameters: Record<string, unknown>;
optional?: boolean;
}

export interface SimpleTaskDef extends CommonTaskDef {
type: TaskType.SIMPLE;
inputParameters?: Record<string, unknown>;
optional?: boolean;
}

export interface SubWorkflowTaskDef extends CommonTaskDef {
Expand All @@ -177,6 +184,7 @@ export interface SubWorkflowTaskDef extends CommonTaskDef {
version?: number;
taskToDomain?: Record<string, string>;
};
optional?: boolean;
}

export interface SwitchTaskDef extends CommonTaskDef {
Expand All @@ -186,6 +194,7 @@ export interface SwitchTaskDef extends CommonTaskDef {
defaultCase: TaskDefTypes[];
evaluatorType: "value-param" | "javascript";
expression: string;
optional?: boolean;
}

export interface TerminateTaskDef extends CommonTaskDef {
Expand All @@ -196,7 +205,6 @@ export interface TerminateTaskDef extends CommonTaskDef {
};
type: TaskType.TERMINATE;
startDelay?: number;
optional?: boolean;
}

export interface WaitTaskDef extends CommonTaskDef {
Expand All @@ -205,6 +213,7 @@ export interface WaitTaskDef extends CommonTaskDef {
duration?: string;
until?: string;
};
optional?: boolean;
}

export interface WorkflowDef
Expand Down
23 changes: 23 additions & 0 deletions src/core/__test__/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ describe("Executor", () => {

expect(workflowStatusAfter.tasks?.[0]?.status).toEqual("COMPLETED");
});

test("Should run workflow with an optional http task", async () => {
const executor = new WorkflowExecutor(await clientPromise);

await executor.registerWorkflow(true, {
name: "test_jssdk_workflow_with_optional_http_task",
version: 1,
ownerEmail: "developers@orkes.io",
tasks: [httpTask("test_jssdk_optional_http_task", { uri: "uncorrect_uri", method: "GET" }, false, true)],
inputParameters: [],
outputParameters: {},
timeoutSeconds: 300,
});

const executionId = await executor.startWorkflow({
name: "test_jssdk_workflow_with_optional_http_task",
input: {},
version: 1,
});

const workflowStatus = await TestUtil.waitForWorkflowStatus(executor, executionId, "COMPLETED");
expect(["FAILED", "COMPLETED_WITH_ERRORS"]).toContain(workflowStatus.tasks?.[0]?.status);
});
});

describe("Execute with Return Strategy and Consistency", () => {
Expand Down
2 changes: 0 additions & 2 deletions src/core/generators/ForkJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const generateJoinTask = (
...nameTaskNameGenerator("join", overrides),
inputParameters: {},
joinOn: [],
optional: false,
asyncComplete: false,
...overrides,
type: TaskType.JOIN,
});
1 change: 0 additions & 1 deletion src/core/generators/TerminateTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const generateTerminateTask = (
workflowOutput: {},
},
startDelay: 0,
optional: false,
...overrides,
type: TaskType.TERMINATE,
});
33 changes: 29 additions & 4 deletions src/core/sdk/__test__/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("forkTask", () => {
const tname = "forkTaskJoin";
const [forkTask, joinTask] = forkTaskJoin(tname, [
eventTask(tname, "prefix", "suffix"),
]);
], true);
expect(forkTask).toEqual({
taskReferenceName: "forkTaskJoin",
name: "forkTaskJoin",
Expand All @@ -135,8 +135,7 @@ describe("forkTask", () => {
taskReferenceName: "forkTaskJoin_join_ref",
inputParameters: {},
joinOn: [],
optional: false,
asyncComplete: false,
optional: true,
type: "JOIN",
});
});
Expand All @@ -150,7 +149,6 @@ describe("httpTask", () => {
method: "GET",
});
expect(httpTaskObj).toEqual({
asyncComplete: false,
name: "httpTask",
taskReferenceName: "httpTask",
inputParameters: {
Expand All @@ -159,6 +157,33 @@ describe("httpTask", () => {
type: "HTTP",
});
});

it("Should create an http task with asyncComplete property", () => {
const httpTaskObj = httpTask("testHttp", { uri: "https://example.com", method: "GET" }, true);
expect(httpTaskObj).toEqual({
name: "testHttp",
taskReferenceName: "testHttp",
inputParameters: {
http_request: { uri: "https://example.com", method: "GET" },
},
asyncComplete: true,
type: "HTTP",
});
});

it("Should create an http task with optional property", () => {
const httpTaskObj = httpTask("testHttp", { uri: "https://example.com", method: "GET" }, false, true);
expect(httpTaskObj).toEqual({
name: "testHttp",
taskReferenceName: "testHttp",
inputParameters: {
http_request: { uri: "https://example.com", method: "GET" },
},
asyncComplete: false,
type: "HTTP",
optional: true,
});
});
});

describe("inlineTask", () => {
Expand Down
8 changes: 6 additions & 2 deletions src/core/sdk/doWhile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { TaskType, DoWhileTaskDef, TaskDefTypes } from "../../common/types";
export const doWhileTask = (
taskRefName: string,
terminationCondition: string,
tasks: TaskDefTypes[]
tasks: TaskDefTypes[],
optional?: boolean
Comment thread
DmitryBorisov-sm marked this conversation as resolved.
): DoWhileTaskDef => ({
name: taskRefName,
taskReferenceName: taskRefName,
loopCondition: terminationCondition,
inputParameters: {},
type: TaskType.DO_WHILE,
loopOver: tasks,
optional,
});

const loopForCondition = (taskRefName: string, valueKey: string) =>
Expand All @@ -19,7 +21,8 @@ const loopForCondition = (taskRefName: string, valueKey: string) =>
export const newLoopTask = (
taskRefName: string,
iterations: number,
tasks: TaskDefTypes[]
tasks: TaskDefTypes[],
optional?: boolean
): DoWhileTaskDef => ({
name: taskRefName,
taskReferenceName: taskRefName,
Expand All @@ -29,4 +32,5 @@ export const newLoopTask = (
},
type: TaskType.DO_WHILE,
loopOver: tasks,
optional,
});
4 changes: 3 additions & 1 deletion src/core/sdk/dynamicFork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { TaskType, ForkJoinDynamicDef, TaskDefTypes } from "../../common/types";
export const dynamicForkTask = (
taskReferenceName: string,
preForkTasks: TaskDefTypes[] = [],
dynamicTasksInput: string = ""
dynamicTasksInput: string = "",
optional?: boolean
): ForkJoinDynamicDef => ({
name: taskReferenceName,
taskReferenceName,
Expand All @@ -14,4 +15,5 @@ export const dynamicForkTask = (
type: TaskType.FORK_JOIN_DYNAMIC,
dynamicForkTasksParam: "dynamicTasks",
dynamicForkTasksInputParamName: "dynamicTasksInput",
optional,
});
16 changes: 11 additions & 5 deletions src/core/sdk/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import { TaskType, EventTaskDef } from "../../common/types";
export const eventTask = (
taskReferenceName: string,
eventPrefix: string,
eventSuffix: string
eventSuffix: string,
optional?: boolean
): EventTaskDef => ({
name: taskReferenceName,
taskReferenceName,
sink: `${eventPrefix}:${eventSuffix}`,
type: TaskType.EVENT,
optional,
});

export const sqsEventTask = (taskReferenceName: string, queueName: string) =>
eventTask(taskReferenceName, "sqs", queueName);
export const sqsEventTask = (
taskReferenceName: string,
queueName: string,
optional?: boolean
) => eventTask(taskReferenceName, "sqs", queueName, optional);

export const conductorEventTask = (
taskReferenceName: string,
eventName: string
) => eventTask(taskReferenceName, "conductor", eventName);
eventName: string,
optional?: boolean
) => eventTask(taskReferenceName, "conductor", eventName, optional);
12 changes: 9 additions & 3 deletions src/core/sdk/forkJoin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { TaskType, ForkJoinTaskDef, TaskDefTypes, JoinTaskDef } from "../../common/types";
import {
TaskType,
ForkJoinTaskDef,
TaskDefTypes,
JoinTaskDef,
} from "../../common/types";
import { generateJoinTask } from "../generators";

export const forkTask = (
Expand All @@ -13,8 +18,9 @@ export const forkTask = (

export const forkTaskJoin = (
taskReferenceName: string,
forkTasks: TaskDefTypes[]
forkTasks: TaskDefTypes[],
optional?: boolean
): [ForkJoinTaskDef, JoinTaskDef] => [
forkTask(taskReferenceName, forkTasks),
generateJoinTask({name:`${taskReferenceName}_join`}),
generateJoinTask({ name: `${taskReferenceName}_join`, optional }),
];
10 changes: 4 additions & 6 deletions src/core/sdk/http.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {
TaskType,
HttpTaskDef,
HttpInputParameters,
} from "../../common/types";
import { TaskType, HttpTaskDef, HttpInputParameters } from "../../common/types";

export const httpTask = (
taskReferenceName: string,
inputParameters: HttpInputParameters,
asyncComplete = false
asyncComplete?: boolean,
optional?: boolean
): HttpTaskDef => ({
name: taskReferenceName,
taskReferenceName,
inputParameters: {
http_request: inputParameters,
},
asyncComplete,
optional,
type: TaskType.HTTP,
});
4 changes: 3 additions & 1 deletion src/core/sdk/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { TaskType, InlineTaskDef } from "../../common/types";
export const inlineTask = (
taskReferenceName: string,
script: string,
evaluatorType: "javascript" | "graaljs" = "javascript"
evaluatorType: "javascript" | "graaljs" = "javascript",
optional?: boolean
): InlineTaskDef => ({
name: taskReferenceName,
taskReferenceName,
Expand All @@ -12,4 +13,5 @@ export const inlineTask = (
expression: script,
},
type: TaskType.INLINE,
optional,
});
4 changes: 3 additions & 1 deletion src/core/sdk/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { TaskType, JoinTaskDef } from "../../common/types";

export const joinTask = (
taskReferenceName: string,
joinOn: string[]
joinOn: string[],
optional?: boolean
): JoinTaskDef => ({
name: taskReferenceName,
taskReferenceName,
joinOn,
type: TaskType.JOIN,
optional,
});
4 changes: 3 additions & 1 deletion src/core/sdk/jsonJq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { TaskType, JsonJQTransformTaskDef } from "../../common/types";

export const jsonJqTask = (
taskReferenceName: string,
script: string
script: string,
optional?: boolean
): JsonJQTransformTaskDef => ({
name: taskReferenceName,
taskReferenceName,
type: TaskType.JSON_JQ_TRANSFORM,
inputParameters: {
queryExpression: script,
},
optional,
});
4 changes: 3 additions & 1 deletion src/core/sdk/kafkaPublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {

export const kafkaPublishTask = (
taskReferenceName: string,
kafka_request: KafkaPublishInputParameters
kafka_request: KafkaPublishInputParameters,
optional?: boolean
): KafkaPublishTaskDef => ({
taskReferenceName,
name: taskReferenceName,
type: TaskType.KAFKA_PUBLISH,
inputParameters: {
kafka_request,
},
optional,
});
4 changes: 3 additions & 1 deletion src/core/sdk/setVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { TaskType, SetVariableTaskDef } from "../../common/types";

export const setVariableTask = (
taskReferenceName: string,
inputParameters: Record<string, unknown>
inputParameters: Record<string, unknown>,
optional?: boolean
): SetVariableTaskDef => ({
name: taskReferenceName,
taskReferenceName,
type: TaskType.SET_VARIABLE,
inputParameters,
optional,
});
Loading