Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between perfrom_async and delay in Sidekiq?

When reading the Sidekiq Wiki I see the following examples:

From Getting started:

Send a message to be processed asynchronously:

HardWorker.perform_async('bob', 5)

You can also send messages by calling the delay method on a class method:

User.delay.do_some_stuff(current_user.id, 20)

Also, from Delayed extensions:

Use delay to deliver your emails asynchronously. Use delay_for(interval) or delay_until(time) to deliver the email at some point in the future.

UserMailer.delay.welcome_email(@user.id) UserMailer.delay_for(5.days).find_more_friends_email(@user.id) UserMailer.delay_until(5.days.from_now).find_more_friends_email(@user.id)

So what is actually the difference between perfrom_async and delay? In which situations would I prefer the one over the other?

like image 289
Alexander Popov Avatar asked May 19 '14 17:05

Alexander Popov


1 Answers

perform_async is Sidekiq's native API. delay is a compatibility API with DelayedJob. Use perform_async when possible.

like image 199
Mike Perham Avatar answered Oct 27 '22 06:10

Mike Perham