How to schedule K2 workflows that run periodically

  • 6 February 2015
  • 13 replies
  • 113 views

Badge +4

Hi,

 

I need to have a K2 workflow run every two hours and do some action. I dont seen any events in the K2 designer workflow that can help me achieve this. How do I achieve this ?

 

Thanks 


13 replies

Badge +7

Hi Tejas,

 

Not sure that this is possible after doing a little asking around and researching -- also, K2 Designer is like the lite version for designing workflows. Would it be possible to use something like K2 Studio? It would provide more robust capabilities. At least in K2 Studio, there is the Activity Start Rule, which could be more along the lines of what you're trying to accomplish. Here's some documentation to look into in case you're interested: https://help.k2.com/onlinehelp/k2blackpearl/userguide/4.6.8/webframe.html#B2.2_Reference_-_Activity_Start_Rule.html

 

Otherwise, if you don't find an adequate solution from somebody, you could log a feature request. 

Userlevel 1
Badge +8

Hi Tejas
 
You can schedule a workflow to run from a K2 Process Portal. 
 
Provided you have SharePoint and have insalled the K2 for SharePoint components you can schedule a process from one of these portals. If you are not using SharePoint/Process Portals then I dont think there is an OOB scheduler. You may have to write a custom service/app to perform this.

 

I cant seem to insert the help files links here but go to help.k2.com and search on "Schedule Process" and look at the first couple of results.

Userlevel 6
Badge +16

Hi,


 


In case you need the link, K2 Process Portal - Scheduler  via the SharePoint 2010 Task scheduler.


 


-khanh-

Badge +10

What you can also do is loop the workflow every two hours. Basically once the workflow has completed the last activity, draw a line from that event t the start activity. then set the start activity start dealy to tow hours. Jsut make sure you put in a condition so that the first time round the 2 hour delay is not applied. THis is all in the workflow s you do not need any of the shareoint stuff. You just need access tot he workspace to start the process.

 

Hope that helps

Userlevel 5
Badge +18

Another option could be to build just a simple application that just references the K2 API to start a process instance:


 


https://www.k2.com/onlinehelp/k2blackpearl/devref/current/webframe.html#Start_Instance_and_Get_Data_Fields.html


 


And then use the windows task scheduler to schedule your application to run every 2 hours:


 


https://technet.microsoft.com/en-us/library/cc748993.aspx

Badge +8

I have done the looping thing, but with a parent process and a sub-process.

 

This way, the "scheduler process" runs and loops on itself (with the 2 hour delay on the start rule), but the sub-processes run independently. There will be a new instance every 2 hours.

Badge +10

Excellent, Although, not a major issue, if your process runs every two hours, thats 12 process istances in a day and 4380 in a year. Just wondering, if you kept the same praent process and looped itself, your K2 database would have less records which would mean it would be cleaner and faster reporting if you use the K2 database for reporting. Although, it not a major issue and quite insignificant, if you have more process that does something similar or run more frequently, then it could add up.

Userlevel 2
Badge +9

Dear s0m3one,


While it may be cleaner in the database to have a single process instance that keeps looping, it is definitely not considered best practice. dgilmour's method of using IPC processes is probably a much better idea. For one thing, if you just keep looping the same instance over and over, the "state" of the instance will continue to grow, which can lead to significant performance issues.


 


Another approach to the problem could be to write an application using the K2 APIs, that programatically starts a workflow. This application could then be scheduled with the Windows scheduler.


 


Best regards,


Gail

Badge +10

Hi Gail,

 

Thanks for the information. I did not know that. I don't understand what you mean by state keeps growing. Would you be able to explain that a bit more or provide some documentation so I can read up.

 

Thanks

Userlevel 2
Badge +9

Dear s0m3one,


 


The "state" of a workflow is persisted in the database. I don't know that there is any real documentation out there, but think of it this way:


 


Each workflow instance has a record in the Server.ProcInst table and the ServerLog.ProcInst table. The STATE column in the database (Server schema) is a binary represenation of the current state of the workflow. It is kind of like a list of every item the process has executed. The more loops a workflow goes through, the larger that STATE field grows. Since it is a binary representation, then every time the server wants to interact with that instance, it has to deserialize that field, and then reserialize it later to write it back to the DB. As such, the larger that STATE grows, the worse the performance of the K2 server can become.


 


Most of the time, a process instance's STATE will be less than 1 MB.


 


I hope this helps explain my earlier comments.


 


Best regards,


Gail

Badge +10

That explains it perfectly. Thank you very much I did not realise the state was stored like that.

 

Badge +4

Hi,

 

How to do all these using K2 scheduling APIs?

 

Regards,

Asad Naeem

Badge +10

I think an API will be great.

 

However I post a while back a Post that explain how to use the Windows Scheduler and securely schedule Loops and Workflows in BlackPearl for reminders and notifications.

 

http://community.k2.com/t5/K2-blackpearl/Ability-to-schedule-Loops-and-Workflows-in-BlackPearl/m-p/86451#M26656

 

Hope this helps =)

Reply