Interruptible periodic timer modeling

Hello,
I have the following use case:

  • A price is computed invoking an external service
  • That price needs to be updated every day at midnight, until the user either purchase it or when the item becomes “unsoldable”
  • When the user purchase it, an activty tree should start (i.e. shipping, receiving payment, etc)

How does one model an interruptible periodic timer? My current approach is to have a check after the timer of a process variable and if this variable has a certain value (i.e. itemUnsoldable==true or itemPurchased==true) that activity tree gets to an end state.

  • Is there a better way?
  • How does one model a timer that triggers “every day at midnight”?

All you need to do is use a timer event with a cycle time.
The engine will run continue/start the process once the time specified has passed.

You can use a cron expression for every day at midnight as follows:
0 0 12 1/1 * ? *

And the other part (like stopping that cycle) should be modeled as I did?thanks

Can you upload your model, it would help me understand what you’re trying to do.

tmp.bpmn (10.6 KB)

Sure, that’s it.Thanks a lot (notice this will run as a subprocess inside a larger procesS)

I think using and Event Sub-process would work best for your use case.

It works like a global listener - as soon as the One per Item subprocess starts the event subprocess will be initialized and run every midnight until the delivery is finished. tmp.bpmn (10.6 KB)

Thanks, that looks like a great improvement. We still have some doubts:

  • When the object expires, the user won’t be able to buy it anymore so we need the overall process to exit. When is a subprocess considered to exit? When all of its activities reach an end state?

  • We need to run the update price also once at the beginning of the process (one per item), how do we do it?

With those two factors in mind i’ve made some changes:

by adding a parallel gateway it will be waiting for a message about purchase while at the same time doing updates.

I’ve also added a terminate end event. (which may be in the wrong place for your use case). In order to demonstrate that if any token reaches that end event the scope will terminate so the token waiting for the purchase message will disappear.

1 Like