Expand my Community achievements bar.

SOLVED

how to wait the end of workflow

Avatar

Level 4

Hi,

After starting a workflow with wfSession.startWorkflow(wfModel, wfData); how can i wait the end of it before the return value?

I'm not able to find the correct function.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

this approach is not going to work well. Because it is not guaranteed that it will finish within that time. Why do want to run the activity as workflow if the user needs to wait anyway for the termination if this process?

kind regards,
Jörg

View solution in original post

10 Replies

Avatar

Community Advisor

Hi Sam,

If you know the exact time that will take to execute your workflow, then one way of achieving is using "Thread.sleep(<time in millisecond>)" in your current process. Is that possible to provide exact use case?

Thanks

Avatar

Level 10

what is the usecase ?? It depends on how you are using it

Avatar

Level 10

I agree with Lokesh - waiting for a workflow to end all depends on the model. If you have a lot of steps and participants - it will take longer then if its a smaller model that say for example - deletes JCR node content.

If you requirement is  to figure out how long a workflow takes - you can write a custom step that starts a counter when when the workflow starts  (a thread that counts)  and calls another custom step that stops the counter. Then calculate the time. 

Avatar

Level 4

I have a user interface with a button, when the user clicks this button he starts a workflow.

The entire workflow take about 30 seconds / 2 minutes then i need an alert for the user.

Workflow wfInstance = wfSession.startWorkflow(wfModel, wfData); while(wfInstance.isActive()){ log.info("status:"+wfInstance.getState()); Thread.sleep(5000); }

This code prints every 5 seconds the string: status:RUNNING

With the InBox interface i terminate the running instance but in the log i see again: status:RUNNING with an endless loop.

Avatar

Level 10

It depends on your workflow model. Does your workflow model has any participant steps ??

Once you start the workflow programmatically, also check the workflow instance and it status in the console (libs/cq/workflow/content/console.html)

Avatar

Correct answer by
Employee Advisor

Hi,

this approach is not going to work well. Because it is not guaranteed that it will finish within that time. Why do want to run the activity as workflow if the user needs to wait anyway for the termination if this process?

kind regards,
Jörg

Avatar

Level 4

Only default step + process step (This process has only a print to console).

I can complete correctly the workflow but the log has ever the string status:RUNNING

Avatar

Level 10

ook.. Have you made sure to check 'Handle Advance' check box in your process step ? Unless that it doesnt completes the workflow !

Avatar

Level 4

I have already checked this checkbox.

The workflow end correctly, it is the code above that doesn't work. It seems that the variable isn't refreshed.

Avatar

Level 10

When you say workflow end correctly, did you check if the instances are not present in the console ??

Also, are you seeing any error messages in the log ?