Wondering if there is a way to make logic within a workflow implementation sleep.
My use case is I have a workflow which executes logic only if the payload is not in use by other workflows, if it is in use the program
will sleep then re-check if it's in use and continue on with logic.
Thanks
Solved! Go to Solution.
Hello -
As Jorg mentioned it is bad practice to have any Thread.sleep() calls in your workflow processes - this will cause workflow threads to be stalled, and if many of these thread.sleep() calls occur simultaneously you could be effectively stopping workflow processing completely.
The correct approach here is to use an ExternalProcessStep [0] to wait until the correct time to execute your process step. You can either execute your code in the execute method if you do not need to wait (return null) or execute your code in the "hasFinished" or "handleResult" methods if you must wait for other workflows to finish.
Also, I wouldn't worry about having multiple workflows running for the same payload - this is typically fine - what you want to avoid (and we have hooks for in the system as Jorg mentioned) is to have the same workflow model running for the same payload. In this case it seems it's different workflow models which are running.
Hope this helps,
Will
That could easily be done using a custom step and Java logic. You could even write a dialog for the step that would allow an author to set the time. Here is an article that shows how to write a custom step with a dialog.
http://scottsdigitalcommunity.blogspot.ca/2015/04/creating-aem-custom-worflow-step-with.html
Hope this helps...
Views
Replies
Total Likes
Hi thanks for an answer but I'd like to keep it within the same step and java logic if possible. Rather than adding in an extra step. My model contains one step anyways.
I tried the following but didn't work:
Thread.currentThread(); Thread.sleep(1000l);
Also note this is within an Workflow process step
Views
Replies
Total Likes
I am not clear - you want part of the workflow to have a delay - but not between steps?
Views
Replies
Total Likes
Yes exactly that
Views
Replies
Total Likes
Is your current 1 step model a custom step that uses Java?
Views
Replies
Total Likes
Yes it is, I tried Thread.sleep(1000l) and did not work.
Views
Replies
Total Likes
Hi,
If you use a programatic sleep in a workflow step, you block the thread of the workflow engine for this time. So if this situation happens often, you will limit your overall workflow performance.
On the other hand, a payload (a node) should never be part of multiple concurrently running workflows. While it is not really enforced on lowlevel, there are highlevel mechanics which should prevent that. So is this just a proactive activity or do you have real problems with a node being the payload of concurrent workflow instances?
Jörg
Hello -
As Jorg mentioned it is bad practice to have any Thread.sleep() calls in your workflow processes - this will cause workflow threads to be stalled, and if many of these thread.sleep() calls occur simultaneously you could be effectively stopping workflow processing completely.
The correct approach here is to use an ExternalProcessStep [0] to wait until the correct time to execute your process step. You can either execute your code in the execute method if you do not need to wait (return null) or execute your code in the "hasFinished" or "handleResult" methods if you must wait for other workflows to finish.
Also, I wouldn't worry about having multiple workflows running for the same payload - this is typically fine - what you want to avoid (and we have hooks for in the system as Jorg mentioned) is to have the same workflow model running for the same payload. In this case it seems it's different workflow models which are running.
Hope this helps,
Will
One simple way is to assign the workflow step to admin so that the user won't see it in his / her inbox with an appropriate step name such as "Waiting for something" and programmatically completing the step using Workflow API once the dependent process is completed.
Please revert if my response didn't help or mark answered if it helped!
Views
Replies
Total Likes
Views
Likes
Replies