gush icon indicating copy to clipboard operation
gush copied to clipboard

Polling scenario in job

Open arrowcircle opened this issue 3 years ago • 5 comments

Hey! Is it possible to implement this:

  • Check URL every minute until result is present or by global timeout
  • Continue workflow when result is available

What is the proper way of doing such a thing with gush?

arrowcircle avatar Jan 17 '23 12:01 arrowcircle

Hello!

It's not strictly possible to build an explicit workflow that loops because we use acyclic graphs underneath, but you could make a blocking job that loops inside it waiting on data to appear.

There was an idea for branching workflows but it was never fleshed out https://github.com/chaps-io/gush/issues/65

pokonski avatar Jan 17 '23 14:01 pokonski

@pokonski Thanks for the answer. My initial thought was to fail job if data is not ready, so it's restarted later. Will this work?

arrowcircle avatar Jan 18 '23 05:01 arrowcircle

That is right! Failed jobs do not enqueue further jobs of the workflow, so you can use it as a short circuit :) (Source: https://github.com/chaps-io/gush/blob/master/lib/gush/worker.rb#L23)

pokonski avatar Jan 18 '23 09:01 pokonski

Thanks, is there any proper way of failing a job and schedule it without raising error notifications system and with the compliance with gush API?

arrowcircle avatar Jan 18 '23 10:01 arrowcircle

That topic is outside of Gush, it raises an exception inside the job, you can rescue from it in ActiveJob https://api.rubyonrails.org/classes/ActiveJob/Exceptions.html

pokonski avatar Jan 18 '23 10:01 pokonski