user16012143
user16012143

Reputation: 131

Sidekiq - Enqueuing a job to be performed 0.seconds from now

I'm using sidekiq for background job and I enqueue a job like this:

SampleJob.set(wait: waiting_time.to_i.seconds).perform_later(***) ・・・ ①

When waiting_time is nil, it becomes

SampleJob.set(wait: 0.seconds).perform_later(***) 

Of course it works well, but I'm worried about performance because worker enqueued with wait argument is derived by poller, so I wonder if I should remove set(wait: waiting_time.to_i.seconds) when waiting_time is nil.

i.e.)

if waiting_time.present?
  SampleJob.set(wait: waiting_time.to_i.seconds).perform_later(***)
else
  SampleJob.perform_later(***)
end ・・・ ②

Is there any differences in performance or speed between ① and ②? Thank you in advance.

Upvotes: 0

Views: 1289

Answers (1)

AJcodez
AJcodez

Reputation: 34146

There is no difference. It looks like this is already considered in the Sidekiq library.

https://github.com/mperham/sidekiq/blob/main/lib/sidekiq/worker.rb#L261

# Optimization to enqueue something now that is scheduled to go out now or in the past
@opts["at"] = ts if ts > now

Upvotes: 2

Related Questions