workflows icon indicating copy to clipboard operation
workflows copied to clipboard

Is it possible to delay a Workflow?

Open MCKLtech opened this issue 4 years ago • 10 comments

I'm wondering about the feasibility of delaying a workflow? For example, wait one hour, then send an email, wait two days, send another email.

Would a custom trigger that calls itself at a later point in time be a potential solution?

MCKLtech avatar Jan 24 '22 17:01 MCKLtech

Hey, MCKLtech yes I would go with a custom trigger for this. I have this feature on the plate but need more time to implement it. If you have a good idea feel free to make a Pull Request. You can contact me anytime about this.

Max-Hutschenreiter avatar Jan 27 '22 10:01 Max-Hutschenreiter

Thank you for the reply, Max, I appreciate it. I have a few follow up questions:

  • In the Trigger class, I assume to delay the start we could simply override the start() method to include a delay in the ProcessWorkflow::dispatch() (A caveat I can think of here is a user may wish to cancel a pending trigger but this would be secondary)

  • Another question is how to delay between tasks e.g.

Trigger -> Task -> Task -> Delay -> Task -> Delay -> Task

It seems that ProcessWorkflow will go through the entire workflow so although we can delay the start, we can't delay during the execution. The only way I can think of doing this would be to have multiple workflows, so if we took the example above, it would become three separate workflows:

A) Trigger -> Task -> Task

B) Trigger (Delay) -> Task

c) Trigger (Delay) -> Task

Where the last task calls the trigger of the next workflow e.g. The last task in A, triggers workflow B, which in turn triggers workflow C

Therefore, is it possible to write a task that calls the trigger of a particular workflow? And if we did, can we pass data between them? Or is there an easier way to do this?

MCKLtech avatar Jan 27 '22 16:01 MCKLtech

I think the best way would be to put a delay function to the Tasks (and Triggers). This saves a serialized version from the DataBus to a new table. The DataBus serialization should not store the complete models but just a reference to it. The other data should get saved. It also needs to know from which task the execution should continue. And now comes the nice part you could write a new trigger that checks this table regularly for a timestamp and a task that continues the given workflow.

Max-Hutschenreiter avatar Jan 28 '22 08:01 Max-Hutschenreiter

I quite like that idea. Do you have any work on it? I'd be happy to help if there was an existing PR or branch.

MCKLtech avatar Jan 31 '22 17:01 MCKLtech

unfortunately, I have not started and don't know when I will have enough time.

Max-Hutschenreiter avatar Feb 02 '22 08:02 Max-Hutschenreiter

This project is amazing! I'd like to use it but I'd like to know if it is still alive. I just fixed an issue about conditions in Tasks. How about delay discussed here? Is there a branch to work on?

makroxyz avatar Feb 16 '23 14:02 makroxyz

+1. I looked at this last year but could never get it working to my satisfaction. I'd be happy to help if @Max-Hutschenreiter had any suggestions

MCKLtech avatar Feb 16 '23 14:02 MCKLtech

I just forked repo.. and I must fix composer.json (added laravel/pint and laravel/slack-notification-channel) and create a ConditionFailedError class that was missing.

Do you have a branch on which we can collaborate?

makroxyz avatar Feb 16 '23 14:02 makroxyz

Hey, it's still alive :) Feel free to make a pull request for your changes. Unfortunately, I am a little short on time, but the Workflow will also get some improvements soon.

Max-Hutschenreiter avatar Feb 24 '23 07:02 Max-Hutschenreiter

I am looping back on this as I've had another project this would be well suited for. However, we need to be able to delay the workflow and know the position as per #23

MCKLtech avatar Jun 06 '23 15:06 MCKLtech