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

Conversation

Michaelpalacce
Copy link
Collaborator

Description

@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.
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) {
	}
}

Will give the following:

image image image

Checklist

  • I have added relevant error handling and logging messages to help troubleshooting
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation, relevant usage information (if applicable)
  • I have updated the PR title with affected component, related issue number and a short summary of the changes introduced
  • I have added labels for implementation kind (kind/) and version type (version/)
  • I have tested against live environment, if applicable
  • I have synced any structure and/or content vRA-NG improvements with vra-ng and ts-vra-ng archetypes (if applicable)
  • I have my changes rebased and squashed to the minimal number of relevant commits. Notice: don't squash all commits
  • I have added a descriptive commit message with a short title, including a Fixed #XXX - or Closed #XXX - prefix to auto-close the issue

Testing

e2e tests added to the pr and screenshots as proof it works

Fixed #337

Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
@Michaelpalacce Michaelpalacce added area/vro-types Relates to changes to the type definitions lang/typescript Related to typescript code area/vrotsc Relates to `vrotsc` module version/minor Introduces a non-breaking feature or change kind/feature New Feature to the project labels Jul 19, 2024
@Michaelpalacce Michaelpalacce self-assigned this Jul 19, 2024
@Michaelpalacce Michaelpalacce requested a review from a team as a code owner July 19, 2024 15:22
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
}

/**
* Default source file printer will directly print the source file with the method node body statements.
*/
export class DefaultSourceFilePrinter implements SourceFilePrinter {
public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string {
public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string {
Copy link
Contributor

@akantchev akantchev Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The itemInfo parameter should be optional (as in the interface it is optional).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interface it should not be optional, will fix it

…re-aria into feature/337-canvas-item-for-scheduled-workflow

Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
*/
export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasItemDecoratorStrategy {
constructor(private readonly sourceFilePrinter: SourceFilePrinter = new ScheduledWorkflowItemSourceFilePrinter()) { }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea to add JSDoc to each of the public methods.

@RootItem()
public start() {
System.log("Starting workflow");
=======
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove (probably leftover from the merge conflict).

itemInfo.target = propValue;
break;

case "exception":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you didn't declare the exception parameter in the vro-types/vrotsc-annotations/index.d.ts nor you're handling it in the decorator. You should remove this case if you don't need to handle the exception parameter.

Michaelpalacce and others added 4 commits July 22, 2024 17:24
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Alexander Kantchev <akantchev@vmware.com>
Signed-off-by: Alexander Kantchev <akantchev@vmware.com>
@akantchev akantchev self-requested a review July 23, 2024 08:36
@Michaelpalacce Michaelpalacce merged commit a0199d1 into main Jul 23, 2024
14 checks passed
@VenelinBakalov VenelinBakalov deleted the feature/337-canvas-item-for-scheduled-workflow branch July 29, 2024 09:15
@VenelinBakalov VenelinBakalov changed the title [vrotsc, vrotsc-annotations], (#337) Canvas Item For Scheduled Workflow [vrotsc, vrotsc-annotations] (#337) Add Workflow canvas Scheduled Workflow item Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vro-types Relates to changes to the type definitions area/vrotsc Relates to `vrotsc` module kind/feature New Feature to the project lang/typescript Related to typescript code version/minor Introduces a non-breaking feature or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canvas item decorator for Scheduled Workflow
2 participants