Ensuring some jobs run in a particular order

122 views
Skip to first unread message

Amadeus Folego

unread,
Jul 29, 2015, 4:59:23 PM7/29/15
to Sidekiq
I am sorry if the solution to my question is already available somewhere, I don't know what specifically to search for.

Anyway, this is my problem:

I am using Sidekiq to notify 3rd party services about status callbacks, let's create a simple example:

A candidate has one of the following statuses: invited, started, finished.

When a candidate perform certain operations, his status changes, at this occasion I enqueue a job to notify my partner, with the candidate id and status as arguments.

My problem is that I need to ensure that, for jobs with the same candidate id, the order at which they were enqueued is the same as they are executed.

On the worst case the 'started' notification can fail for some reason and when the service is restored the 'finished' notification is run first.

Is there any feature of Sidekiq or Sidekiq Pro that may help me enforce such a behaviour?

Thanks, Amadeus.

Mike Perham

unread,
Jul 29, 2015, 6:49:18 PM7/29/15
to sid...@googlegroups.com
Your question boils down to "how do I ensure my model goes through a sequence of steps in order?"

You should model your candidate status workflow with a state machine, e.g. https://github.com/troessner/transitions

If the Invited job fails for some reason, the Finished job should blow up with InvalidTransitionError because the candidate has not been invited yet.  The Finished job will continue to retry until the Invited job runs successfully.

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/18191d1d-3a38-45ff-8a5a-81f4c3606721%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

Amadeus Folego

unread,
Jul 29, 2015, 7:00:03 PM7/29/15
to sid...@googlegroups.com
Hi Mike!

Thanks for the help.

On Wed, Jul 29, 2015 at 03:49:17PM -0700, Mike Perham wrote:
> Your question boils down to "how do I ensure my model goes through a sequence
> of steps in order?"
>
> You should model your candidate status workflow with a state machine, e.g.
> https://github.com/troessner/transitions

My problem is not related to validation of state transitions.

The transitions are working fine, I don't use my sidekiq workers to
perform them, just to notify my partner that a transition has
occurred.

In this context it's really simple: I just need to make sure that the
job which notifies 'finished' does not run for any reason before
'started'.

I am sorry if my question is not clear enough, let me know if you have
any questions.

Mike Perham

unread,
Jul 29, 2015, 7:02:21 PM7/29/15
to sid...@googlegroups.com
You want a "notification_status" attribute then which the jobs do set.  Same difference.

:none -> :started -> :finished

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Amadeus Folego

unread,
Jul 29, 2015, 8:35:58 PM7/29/15
to sid...@googlegroups.com
On Wed, Jul 29, 2015 at 04:02:20PM -0700, Mike Perham wrote:
> You want a "notification_status" attribute then which the jobs do set.  Same
> difference.
>
> :none -> :started -> :finished

Thanks Mike but this is not what I am looking for.

What I am looking for is very simple, I just wanted to know if there was
a way to ensure that a job would only be performed if a condition was
satisfied. I can do it in a ugly manner, I just wanted to do if there
was already something that could help me.

Thanks for the attention, sorry for wasting your time.
Reply all
Reply to author
Forward
0 new messages