17

According to ActiveJob docs to enqueue a job I should use perform_later. Sidekiq docs implement perform_async, but the ActiveJob part of the docs suggests using perform_later. I've used perform_async previously in Rails, so do these differ in any way or is it just convention?

sloneorzeszki
  • 1,274
  • 3
  • 12
  • 22

1 Answers1

31

ActiveJob is a wrapper around the most known background job gems to provide a base API to work with background jobs.

ActiveJob defines perform_later. Sidekiq defines perfom_async. Which method you use depends on how you implemente your workers. If you use ActiveJob workers then you must use perform_later, if you don't use ActiveJob and just go with plain Sidekiq workers then use perform_async.

arieljuod
  • 15,460
  • 2
  • 25
  • 36
  • Is one way of implementing the workers recommended over the other? Does `perform_async` provide something that `perform_later` doesn't? I imagine that if I needed to move from Sidekiq to different queuing backend then `perform_later` would be a better choice. – sloneorzeszki Apr 23 '19 at 06:30
  • 1
    I'm not sure if both methods are 100% equivalent since the code is different, but I guess you'll have almost the same features. Don't overthink it, if you need something from `perform_async` that's not provided by `perform_later` you can surelly implement what you need. It's a good practice to use ActiveJob, you don't need to worry about the background processing method, just code with a single interface and change the provider. Of course you could just use Sidekiq with no ActiveJob in the middle, but it would be a problem for the future if you need to change to another processing method. – arieljuod Apr 23 '19 at 13:25
  • 2
    You can even have workers implemented with ActiveJob and other with plain Sidekiq if you really need some special Sidekiq-only feature. – arieljuod Apr 23 '19 at 13:29
  • Be careful with bolting on extra dependencies without a desired reason. [ActiveJob decreases Sidekiq performance significantly](https://github.com/sidekiq/sidekiq/wiki/Active-Job#performance) so the trade off needs to be worthwhile. – SMAG Aug 28 '23 at 11:43