How to find Job created_at time within worker

105 views
Skip to first unread message

Alex Soto

unread,
Jan 29, 2020, 8:22:50 PM1/29/20
to Sidekiq
Hi,

What I'm trying to determine:
As my worker executes, I want to determine whether this current run is 'stale', by checking the created_at of the job vs the db record I expect to update, in case another job has already updated said db record.

Why:

This worker calls an external service, then updates the db record.  Sometimes that service will throttle us causing the job to fail.  I let the exception bubble up and allow sidekiq to retry.  However, due to other actions in the system, that same job may be triggered for the same record.  Therefore, while one job is on the retry timeout, this new job may succeed (not throttled by the service), then when the original job is retried, it no longer needs to do the work.

I try this while the #perform method is running:

::Sidekiq::Queue.new.find_job(jid)

but it's always returning nil.

My job is running on the default queue and my version is:

> ::Sidekiq::VERSION
=> "5.2.7"

Thanks

Mike Perham

unread,
Jan 29, 2020, 8:46:58 PM1/29/20
to sid...@googlegroups.com
Pass Time.now.to_i as an argument to the job and use that to compare with the db updated_at. 

On Jan 29, 2020, at 17:22, Alex Soto <aps...@gmail.com> wrote:


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/220b8fc6-12cf-4b48-9293-707be2988dfd%40googlegroups.com.
Message has been deleted

Alex Soto

unread,
Feb 4, 2020, 2:29:56 AM2/4/20
to Sidekiq
Thanks that helped


On Wednesday, January 29, 2020 at 5:46:58 PM UTC-8, Mike Perham wrote:
Pass Time.now.to_i as an argument to the job and use that to compare with the db updated_at. 

On Jan 29, 2020, at 17:22, Alex Soto <aps...@gmail.com> wrote:


Hi,

What I'm trying to determine:
As my worker executes, I want to determine whether this current run is 'stale', by checking the created_at of the job vs the db record I expect to update, in case another job has already updated said db record.

Why:

This worker calls an external service, then updates the db record.  Sometimes that service will throttle us causing the job to fail.  I let the exception bubble up and allow sidekiq to retry.  However, due to other actions in the system, that same job may be triggered for the same record.  Therefore, while one job is on the retry timeout, this new job may succeed (not throttled by the service), then when the original job is retried, it no longer needs to do the work.

I try this while the #perform method is running:

::Sidekiq::Queue.new.find_job(jid)

but it's always returning nil.

My job is running on the default queue and my version is:

> ::Sidekiq::VERSION
=> "5.2.7"

Thanks

--
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 sid...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages