Skip to content

Commit

Permalink
Merge pull request #350 from vmware/feature/337-canvas-item-for-sched…
Browse files Browse the repository at this point in the history
…uled-workflow

[vrotsc, vrotsc-annotations], (#337) Canvas Item For Scheduled Workflow
  • Loading branch information
Michaelpalacce committed Jul 23, 2024
2 parents 2c96994 + 0b383c4 commit a0199d1
Show file tree
Hide file tree
Showing 20 changed files with 653 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,29 @@ 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.
Expand All @@ -154,6 +177,7 @@ import {
WaitingTimerItem,
WorkflowItem,
WorkflowEndItem,
ScheduledWorkflowItem
} from "vrotsc-annotations";

@Workflow({
Expand All @@ -175,6 +199,12 @@ import {
result: {
type: "number",
},
workflowScheduleDate: {
type: "Date"
},
scheduledTask: {
type: "Task"
}
errorMessage: {
type: "string",
},
Expand All @@ -187,9 +217,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 @@ -204,11 +235,24 @@ export class HandleNetworkConfigurationBackup {
// NOOP
}

@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
185 changes: 154 additions & 31 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[//]: # "VERSION_PLACEHOLDER DO NOT DELETE"
[//]: # "Used when working on a new release. Placed together with the Version.md"
[//]: # "Nothing here is optional. If a step must not be performed, it must be said so"
[//]: # "Do not fill the version, it will be done automatically"
[//]: # "Quick Intro to what is the focus of this release"
[//]: # (VERSION_PLACEHOLDER DO NOT DELETE)
[//]: # (Used when working on a new release. Placed together with the Version.md)
[//]: # (Nothing here is optional. If a step must not be performed, it must be said so)
[//]: # (Do not fill the version, it will be done automatically)
[//]: # (Quick Intro to what is the focus of this release)

## Breaking Changes

[//]: # "### *Breaking Change*"
[//]: # "Describe the breaking change AND explain how to resolve it"
[//]: # "You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/"
[//]: # (### *Breaking Change*)
[//]: # (Describe the breaking change AND explain how to resolve it)
[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/)

## Deprecations

[//]: # "### *Deprecation*"
[//]: # "Explain what is deprecated and suggest alternatives"
[//]: # "Features -> New Functionality"
[//]: # (### *Deprecation*)
[//]: # (Explain what is deprecated and suggest alternatives)

[//]: # (Features -> New Functionality)

## Features

[//]: # "### *Feature Name*"
[//]: # "Describe the feature"
[//]: # "Optional But highly recommended Specify *NONE* if missing"
[//]: # "#### Relevant Documentation:"
[//]: # "Improvements -> Bugfixes/hotfixes or general improvements"
[//]: # (### *Feature Name*)
[//]: # (Describe the feature)
[//]: # (Optional But higlhy recommended Specify *NONE* if missing)
[//]: # (#### Relevant Documentation:)

### \*New `DefaultErrorHandler` decorator for Workflows
### *New `DefaultErrorHandler` decorator for Workflows*

This decorator is used to specify a default error handler. It can be bound either to a workflow item component or workflow end.

Expand Down Expand Up @@ -92,7 +92,7 @@ export class HandleDefaultError {
}
```

### \*New `@WorkflowEndItem` decorator for Workflows
### *New `@WorkflowEndItem` decorator for Workflows*

The decorator is used to specify a custom workflow end item.

Expand Down Expand Up @@ -140,7 +140,130 @@ export class WorkflowEnd {
}
```

### \*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, DecisionItem, WaitingTimerItem, WorkflowItem, ScheduledWorkflowItem } from "vrotsc-annotations";

@Workflow({
name: "Example Waiting Timer",
path: "VMware/PSCoE",
attributes: {
waitingTimer: {
type: "Date"
},
counter: {
type: "number"
},
first: {
type: "number"
},
second: {
type: "number"
},
result: {
type: "number"
},
workflowScheduleDate: {
type: "Date"
},
scheduledTask: {
type: "Task"
}
}
})
export class HandleNetworkConfigurationBackup {
@DecisionItem({ target: "waitForEvent", else: "prepareItems" })
public decisionElement(waitingTimer: Date) {
return waitingTimer !== null;
}

@Item({ target: "callOtherWf" })
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({
target: "print",
linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0"
})
public callOtherWf(@In first: number, @In second: number, @Out result: number) {
}


@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) {
counter = 0;
}

counter++;

if (counter < 2) {
const tt = Date.now() + 5 * 1000;
waitingTimer = new Date(tt);
} else {
waitingTimer = null;
}

System.log("Counter: " + counter);
System.log("Waiting Timer: " + waitingTimer);
}

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

@WaitingTimerItem({ target: "execute" })
public waitForEvent(@In waitingTimer: Date) {
}
}
```

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

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

Expand Down Expand Up @@ -245,18 +368,18 @@ export class HandleNetworkConfigurationBackup {

## Improvements

[//]: # "### *Improvement Name* "
[//]: # "Talk ONLY regarding the improvement"
[//]: # "Optional But highly recommended"
[//]: # "#### Previous Behavior"
[//]: # "Explain how it used to behave, regarding to the change"
[//]: # "Optional But highly recommended"
[//]: # "#### New Behavior"
[//]: # "Explain how it behaves now, regarding to the change"
[//]: # "Optional But highly recommended Specify *NONE* if missing"
[//]: # "#### Relevant Documentation:"
[//]: # (### *Improvement Name* )
[//]: # (Talk ONLY regarding the improvement)
[//]: # (Optional But higlhy recommended)
[//]: # (#### Previous Behavior)
[//]: # (Explain how it used to behave, regarding to the change)
[//]: # (Optional But higlhy recommended)
[//]: # (#### New Behavior)
[//]: # (Explain how it behaves now, regarding to the change)
[//]: # (Optional But higlhy recommended Specify *NONE* if missing)
[//]: # (#### Relevant Documentation:)

### _ABX archetype build issue, cannot compile_
### *ABX archetype build issue, cannot compile*

Fixed an issue where the ABX archetype could not compile due to an old version of the `xmlbuilder2` package.

Expand Down Expand Up @@ -300,4 +423,4 @@ The ABX archetype now compiles successfully.

## Upgrade procedure

[//]: # "Explain in details if something needs to be done"
[//]: # (Explain in details if something needs to be done)
54 changes: 54 additions & 0 deletions typescript/vrotsc/e2e/cases/canvas-items/scheduled-workflow.wf.ts
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.

Loading

0 comments on commit a0199d1

Please sign in to comment.