Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vrotsc, vrotsc-annotations] (#337) Add Workflow canvas Scheduled Workflow item #350

Merged
merged 14 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,37 @@ The decorator is used to specify a workflow item that will be called.

In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items.

#### `@ScheduledWorkflowItem`

The decorator is used to specify a scheduled workflow item that will be called.

##### Supported Parameters

- `target` - The name of the next in line item. Same as `@Item`.
- `linkedItem` - The ID of the workflow to schedule.

In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items.

##### Inputs

Special input is needed for the ScheduledWorkflowItem.

- `workflowScheduleDate` - {Date} is required. The name **must** be `workflowScheduleDate`. If this is missing an error is thrown. We don't check if the type is `Date` but Aria Orchestrator will complain.

##### Outputs

Special output is needed for the ScheduledWorkflowItem.

- `scheduledTask` - {Task} is optional. If it's missing nothing will happen, if it's added, then the name **must** be `scheduledTask`. This is the task that is scheduled.

#### `@RootItem`

This is a meta decorator. Add this to whichever function you want to be the entry point of the workflow.

### Example Workflow

```ts
import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations";
import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem, ScheduledWorkflowItem } from "vrotsc-annotations";

@Workflow({
name: "Example Waiting Timer",
Expand All @@ -84,6 +107,12 @@ import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, Work
},
result: {
type: "number"
},
workflowScheduleDate: {
type: "Date"
},
scheduledTask: {
type: "Task"
}
}
})
Expand All @@ -94,9 +123,10 @@ export class HandleNetworkConfigurationBackup {
}

@Item({ target: "callOtherWf" })
public prepareItems(@In @Out first: number, @In @Out second: number) {
public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) {
first = 1;
second = 2;
workflowScheduleDate = System.getDate("1 minute from now", undefined);
}

@WorkflowItem({
Expand All @@ -106,11 +136,24 @@ export class HandleNetworkConfigurationBackup {
public callOtherWf(@In first: number, @In second: number, @Out result: number) {
}

@Item({ target: "end" })

@Item({ target: "scheduleOtherWf" })
public print(@In result: number) {
System.log("Result: " + result);
}

@ScheduledWorkflowItem({
target: "printScheduledDetails",
linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0"
})
public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) {
}

@Item({ target: "end" })
public printScheduledDetails(@In scheduledTask: Task) {
System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`);
}

@Item({ target: "decisionElement", exception: "" })
public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void {
if (!counter) {
Expand Down
83 changes: 82 additions & 1 deletion docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,88 @@

[//]: # (Improvements -> Bugfixes/hotfixes or general improvements)

### *New `WorkflowItem` decorator for Workflows
### *New `ScheduledWorkflowItem` decorator for Workflows*

The new decorator gives you the ability to specify a canvas item that schedules a Workflow.

- `@ScheduledWorkflowItem({target: "", linkedItem: "" })`
- `target` - The name of the next in line item.
- `linkedItem` - The ID of the workflow to schedule

In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items.

#### Inputs

Special input is needed for the ScheduledWorkflowItem.

- `workflowScheduleDate` - {Date} is required. The name **must** be `workflowScheduleDate`. If this is missing an error is thrown. We don't check if the type is `Date` but Aria Orchestrator will complain.

#### Outputs

Special output is needed for the ScheduledWorkflowItem.

- `scheduledTask` - {Task} is optional. If it's missing nothing will happen, if it's added, then the name **must** be `scheduledTask`. This is the task that is scheduled.

#### Example

```ts
import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc-annotations";

@Workflow({
name: "Scheduled Workflow Test",
path: "VMware/PSCoE",
description: "Scheduling another workflow and binding values correctly",
attributes: {
waitingTimer: {
type: "Date"
},
counter: {
type: "number"
},
first: {
type: "number"
},
second: {
type: "number"
},
workflowScheduleDate: {
type: "Date"
},
scheduledTask: {
type: "Task"
}
}
})
export class HandleNetworkConfigurationBackup {
@ScheduledWorkflowItem({
target: "printScheduledDetails",
linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0"
})
public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) {
}

@Item({ target: "scheduleOtherWf" })
public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) {
first = 1;
second = 2;
workflowScheduleDate = System.getDate("1 minute from now", undefined);
}

@Item({ target: "end" })
public printScheduledDetails(@In scheduledTask: Task) {
System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`);
}


@Item({ target: "prepareItems", exception: "" })
@RootItem()
public start() {
System.log("Starting workflow");
}
}
```

### *New `WorkflowItem` decorator for Workflows*

The new Decorator gives you the ability to specify a canvas item that calls a Workflow.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc-annotations";

@Workflow({
name: "Scheduled Workflow Test",
path: "VMware/PSCoE",
description: "Scheduling another workflow and binding values correctly",
attributes: {
waitingTimer: {
type: "Date"
},
counter: {
type: "number"
},
first: {
type: "number"
},
second: {
type: "number"
},
workflowScheduleDate: {
type: "Date"
},
scheduledTask: {
type: "Task"
}
}
})
export class HandleNetworkConfigurationBackup {
@ScheduledWorkflowItem({
target: "printScheduledDetails",
linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0"
})
public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) {
}

@Item({ target: "scheduleOtherWf" })
public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) {
first = 1;
second = 2;
workflowScheduleDate = System.getDate("1 minute from now", undefined);
}

@Item({ target: "end" })
public printScheduledDetails(@In scheduledTask: Task) {
System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`);
}


@Item({ target: "prepareItems", exception: "" })
@RootItem()
public start() {
System.log("Starting workflow");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>Generated by vrotsc</comment>
<entry key="categoryPath">VMware.PSCoE</entry>
<entry key="name">Scheduled Workflow Test</entry>
<entry key="type">Workflow</entry>
<entry key="id">18b56581-f9ac-30cb-8df2-8c1c7e5dba37</entry>
</properties>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?><workflow xmlns="http://vmware.com/vco/workflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://vmware.com/vco/workflow http://vmware.com/vco/workflow/Workflow-v4.xsd" root-name="item4" object-name="workflow:name=generic" id="18b56581-f9ac-30cb-8df2-8c1c7e5dba37" version="1.0.0" api-version="6.0.0" restartMode="1" resumeFromFailedMode="0"><display-name><![CDATA[Scheduled Workflow Test]]></display-name><description><![CDATA[Scheduling another workflow and binding values correctly]]></description><position x="105" y="45.90909090909091" /><attrib name="waitingTimer" type="Date" read-only="false" /><attrib name="counter" type="number" read-only="false" /><attrib name="first" type="number" read-only="false" /><attrib name="second" type="number" read-only="false" /><attrib name="workflowScheduleDate" type="Date" read-only="false" /><attrib name="scheduledTask" type="Task" read-only="false" /><workflow-item name="item0" type="end" end-mode="0"><position x="905.0" y="45.40909090909091" /></workflow-item><workflow-item name="item1" out-name="item3" type="task" launched-workflow-id="9e4503db-cbaa-435a-9fad-144409c08df0"><script encoded="false"><![CDATA[var workflowParameters = new Properties(), workflowToLaunch = Server.getWorkflowWithId("9e4503db-cbaa-435a-9fad-144409c08df0");
if (workflowToLaunch == null) {
throw "Workflow not found";
}
workflowParameters.put("first", first);
workflowParameters.put("second", second);
scheduledTask = workflowToLaunch.schedule(workflowParameters, workflowScheduleDate, undefined, undefined);
]]></script><display-name><![CDATA[scheduleOtherWf]]></display-name><in-binding><bind name="first" type="number" export-name="first" /><bind name="second" type="number" export-name="second" /><bind name="workflowScheduleDate" type="Date" export-name="workflowScheduleDate" /></in-binding><out-binding><bind name="scheduledTask" type="Task" export-name="scheduledTask" /></out-binding><position x="225.0" y="55.40909090909091" /></workflow-item><workflow-item name="item2" out-name="item1" type="task"><script encoded="false"><![CDATA[first = 1;
second = 2;
workflowScheduleDate = System.getDate("1 minute from now", undefined);
]]></script><display-name><![CDATA[prepareItems]]></display-name><in-binding><bind name="first" type="number" export-name="first" /><bind name="second" type="number" export-name="second" /><bind name="workflowScheduleDate" type="Date" export-name="workflowScheduleDate" /></in-binding><out-binding><bind name="first" type="number" export-name="first" /><bind name="second" type="number" export-name="second" /><bind name="workflowScheduleDate" type="Date" export-name="workflowScheduleDate" /></out-binding><position x="385.0" y="55.40909090909091" /></workflow-item><workflow-item name="item3" out-name="item0" type="task"><script encoded="false"><![CDATA[System.log("Scheduled task: ".concat(scheduledTask.id, ", [").concat(scheduledTask.state, "]"));
]]></script><display-name><![CDATA[printScheduledDetails]]></display-name><in-binding><bind name="scheduledTask" type="Task" export-name="scheduledTask" /></in-binding><position x="545.0" y="55.40909090909091" /></workflow-item><workflow-item name="item4" out-name="item2" type="task"><script encoded="false"><![CDATA[System.log("Starting workflow");
]]></script><display-name><![CDATA[start]]></display-name><position x="705.0" y="55.40909090909091" /></workflow-item><presentation></presentation></workflow>
8 changes: 8 additions & 0 deletions typescript/vrotsc/src/compiler/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export enum WorkflowItemType {
* It can target a specific item and accepts input and output bindings
*/
Workflow = "WorkflowItem",

/**
* This item type represents a scheduled workflow item
*
* It can target a specific item and accepts input bindings
* There is only one outputBinding if you want to get the scheduledTask information
*/
ScheduledWorkflow = "ScheduledWorkflowItem"
}

/////////////////////////////////// Polyglot Decorator ///////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import RootItemDecoratorStrategy from "./decorators/rootItemDecoratorStrategy";
import WaitingTimerItemDecoratorStrategy from "./decorators/waitingTimerItemDecoratorStrategy";
import DecisionItemDecoratorStrategy from "./decorators/decisionItemDecoratorStrategy";
import WorkflowItemDecoratorStrategy from "./decorators/workflowItemDecoratorStrategy";
import ScheduledWorkflowItemDecoratorStrategy from "./decorators/scheduledWorkflowItemDecoratorStrategy";

/**
* Fetches details from the decorators for the methods and adds the information to the Descriptors
Expand Down Expand Up @@ -84,6 +85,8 @@ function getItemStrategy(decoratorNode: ts.Decorator): CanvasItemDecoratorStrate
return new WorkflowItemDecoratorStrategy();
case WorkflowItemType.RootItem:
return new RootItemDecoratorStrategy();
case WorkflowItemType.ScheduledWorkflow:
return new ScheduledWorkflowItemDecoratorStrategy();
default:
throw new Error(`Invalid decorator type: ${identifierText}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default interface CanvasItemDecoratorStrategy {
*
* The rest can return an empty string.
*/
printSourceFile(methodNode: ts.MethodDeclaration, sourceFile: ts.SourceFile): string;
printSourceFile(methodNode: ts.MethodDeclaration, sourceFile: ts.SourceFile, itemInfo: WorkflowItemDescriptor): string;

printItem(itemInfo: WorkflowItemDescriptor, pos: number): string;
}
Expand Down
Loading
Loading