Skip to main content

We would like to have our workflow kick off a long-running job. It may take up to 45 minutes. We would then like the workflow to continue once that job finishes.

 

Can anyone recommend an approach to do that? We can implement the job in .NET so we have some options, and our preferred way to host it would be in a self-hosted webapi service that K2 connects to using a REST SmartObject. We're not 100% attached to this approach though.

 

Is there a pattern or a way to launch long running asynchronous jobs from a workflow? We could possibly write the job status to a database table and loop the workflow to check it and continue on when the status is "done".

 

Any suggestions would be welcome. Thank you.

Hi,


 


I don't recommend using REST as well, as that means you will need to maintain a constant connection to your REST service until it returns a result.


 


You can definitely explore writing the job status to a somewhere, then get the workflow to check that job status. However, I do not recommend using a loop, as it will incur additional overheads. Imagine your workflow going through countless loops for 45 minutes. This is not what the loop is designed for as well.


 


If you are on K2 Five, you can use the Timer Step. After you have executed the job asynchronously, you can link it to a Timer Step, which will pause your workflow path for a specific amount of time. Once the path restarts, check if the job has completed. If not, draw the line back to the Timer Step.


 


We ended up on the phone with a remote services resource. K2 has a way to make asynchronous calls from within the workflow. It's documented here (for 5.2): https://help.k2.com/onlinehelp/K2Cloud/UserGuide/Update_9/default.htm#How-Tos/WaitExternal/Wait-External-System.htm

 

The basic idea is that you fire off a message to your service to tell it to start the long-running process, passing it the workflow step's serial number. As with any asynchronous situation, that endpoint immediately returns a response to K2, but in the background it's doing the long-running thing.

 

When that endpoint is done, it calls a K2 system endpoint to tell it that it's done and it passes back the serial number from before. That's how the WF engine knows that the async process is complete and that it can carry on.

 

This is all documented right from a "learn more" type link right in the workflow step next to the "wait for external system" option. You have to go a couple of levels deep to get the real juice but it's there. We didn't know where to look.


Reply