99} from "../sdk" ;
1010import { cleanupWorkflowsAndTasks } from "./utils/cleanup" ;
1111import { waitForWorkflowStatus } from "./utils/waitForWorkflowStatus" ;
12+ import { describeForOrkesV5 } from "./utils/customJestDescribe" ;
1213
1314describe ( "TaskRunner" , ( ) => {
1415 const clientPromise = orkesConductorClient ( ) ;
@@ -26,85 +27,87 @@ describe("TaskRunner", () => {
2627 ) ;
2728 } ) ;
2829
29- test ( "worker example " , async ( ) => {
30- const client = await clientPromise ;
31- const executor = new WorkflowExecutor ( client ) ;
32- const taskName = `jsSdkTest-task-manager-int-test-${ Date . now ( ) } ` ;
33- const workflowName = `jsSdkTest-task-manager-int-test-wf-${ Date . now ( ) } ` ;
30+ describeForOrkesV5 ( "worker example (requires update-v2)" , ( ) => {
31+ test ( "worker example " , async ( ) => {
32+ const client = await clientPromise ;
33+ const executor = new WorkflowExecutor ( client ) ;
34+ const taskName = `jsSdkTest-task-manager-int-test-${ Date . now ( ) } ` ;
35+ const workflowName = `jsSdkTest-task-manager-int-test-wf-${ Date . now ( ) } ` ;
3436
35- const taskRunner = new TaskRunner ( {
36- client : client ,
37- worker : {
38- taskDefName : taskName ,
39- execute : async ( ) => {
40- return {
41- outputData : {
42- hello : "From your worker" ,
43- } ,
44- status : "COMPLETED" ,
45- } ;
37+ const taskRunner = new TaskRunner ( {
38+ client : client ,
39+ worker : {
40+ taskDefName : taskName ,
41+ execute : async ( ) => {
42+ return {
43+ outputData : {
44+ hello : "From your worker" ,
45+ } ,
46+ status : "COMPLETED" ,
47+ } ;
48+ } ,
4649 } ,
47- } ,
48- options : {
49- pollInterval : 1000 ,
50- domain : undefined ,
51- concurrency : 2 ,
52- workerID : "" ,
53- } ,
54- } ) ;
55- taskRunner . startPolling ( ) ;
56-
57- expect ( taskRunner . isPolling ) . toEqual ( true ) ;
50+ options : {
51+ pollInterval : 1000 ,
52+ domain : undefined ,
53+ concurrency : 2 ,
54+ workerID : "" ,
55+ } ,
56+ } ) ;
57+ taskRunner . startPolling ( ) ;
5858
59- await executor . registerWorkflow ( true , {
60- name : workflowName ,
61- version : 1 ,
62- ownerEmail : "developers@orkes.io" ,
63- tasks : [ simpleTask ( taskName , taskName , { } ) ] ,
64- inputParameters : [ ] ,
65- outputParameters : { } ,
66- timeoutSeconds : 0 ,
67- } ) ;
68- workflowsToCleanup . push ( { name : workflowName , version : 1 } ) ;
59+ expect ( taskRunner . isPolling ) . toEqual ( true ) ;
6960
70- const { workflowId : executionId } = await executor . executeWorkflow (
71- {
61+ await executor . registerWorkflow ( true , {
7262 name : workflowName ,
7363 version : 1 ,
74- } ,
75- workflowName ,
76- 1 ,
77- `${ workflowName } -id`
78- ) ;
79- expect ( executionId ) . toBeDefined ( ) ;
64+ ownerEmail : "developers@orkes.io" ,
65+ tasks : [ simpleTask ( taskName , taskName , { } ) ] ,
66+ inputParameters : [ ] ,
67+ outputParameters : { } ,
68+ timeoutSeconds : 0 ,
69+ } ) ;
70+ workflowsToCleanup . push ( { name : workflowName , version : 1 } ) ;
8071
81- taskRunner . updateOptions ( { concurrency : 1 , pollInterval : 100 } ) ;
72+ const { workflowId : executionId } = await executor . executeWorkflow (
73+ {
74+ name : workflowName ,
75+ version : 1 ,
76+ } ,
77+ workflowName ,
78+ 1 ,
79+ `${ workflowName } -id`
80+ ) ;
81+ expect ( executionId ) . toBeDefined ( ) ;
8282
83- expect ( executionId ) . toBeDefined ( ) ;
84- if ( ! executionId ) {
85- throw new Error ( "Execution ID is undefined" ) ;
86- }
83+ taskRunner . updateOptions ( { concurrency : 1 , pollInterval : 100 } ) ;
8784
88- const workflowStatus = await waitForWorkflowStatus (
89- executor ,
90- executionId ,
91- "COMPLETED"
92- ) ;
85+ expect ( executionId ) . toBeDefined ( ) ;
86+ if ( ! executionId ) {
87+ throw new Error ( "Execution ID is undefined" ) ;
88+ }
9389
94- const [ firstTask ] = workflowStatus . tasks || [ ] ;
95- expect ( firstTask ?. taskType ) . toEqual ( taskName ) ;
96- expect ( workflowStatus . status ) . toEqual ( "COMPLETED" ) ;
90+ const workflowStatus = await waitForWorkflowStatus (
91+ executor ,
92+ executionId ,
93+ "COMPLETED"
94+ ) ;
9795
98- await taskRunner . stopPolling ( ) ;
96+ const [ firstTask ] = workflowStatus . tasks || [ ] ;
97+ expect ( firstTask ?. taskType ) . toEqual ( taskName ) ;
98+ expect ( workflowStatus . status ) . toEqual ( "COMPLETED" ) ;
9999
100- expect ( taskRunner . isPolling ) . toEqual ( false ) ;
101- const taskDetails = await executor . getTask ( firstTask ?. taskId || "" ) ;
102- expect ( taskDetails ?. status ) . toEqual ( "COMPLETED" ) ;
100+ await taskRunner . stopPolling ( ) ;
103101
104- const metadataClient = new OrkesClients ( client ) . getMetadataClient ( ) ;
105- await cleanupWorkflowsAndTasks ( metadataClient , {
106- workflows : [ { name : workflowName , version : 1 } ] ,
107- tasks : [ taskName ] ,
108- } ) ;
109- } , 120000 ) ;
102+ expect ( taskRunner . isPolling ) . toEqual ( false ) ;
103+ const taskDetails = await executor . getTask ( firstTask ?. taskId || "" ) ;
104+ expect ( taskDetails ?. status ) . toEqual ( "COMPLETED" ) ;
105+
106+ const metadataClient = new OrkesClients ( client ) . getMetadataClient ( ) ;
107+ await cleanupWorkflowsAndTasks ( metadataClient , {
108+ workflows : [ { name : workflowName , version : 1 } ] ,
109+ tasks : [ taskName ] ,
110+ } ) ;
111+ } , 120000 ) ;
112+ } ) ;
110113} ) ;
0 commit comments