how to wait the end of workflow | Community
Skip to main content
Level 4
October 16, 2015
Solved

how to wait the end of workflow

  • October 16, 2015
  • 10 replies
  • 2480 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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

10 replies

Siva_Sogalapalli
Community Advisor
Community Advisor
October 16, 2015

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

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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

smacdonald2008
Level 10
October 16, 2015

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. 

Level 4
October 16, 2015

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.

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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)

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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

Level 4
October 16, 2015

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

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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

Level 4
October 16, 2015

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.

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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 ?