11

I need to implement some background processing to 1) send emails, 2) do some API calls. And, whatever system I use, I'll also be combining with some kind of cron scheduler (Whenever likely). I'm curious, I recognize that there's an array of really cool background processing gems (Delayed Job, Sidekiq, Resque), but I also understand that you can do background processing with just a rake task per Ryan Bate's video: http://railscasts.com/episodes/127-rake-in-background.

What are the pro/cons of using a gem VS a rake task to background process? One thing about the latter that is concerning to me is that you have to spin up a new environment every time a rake task is called, which is terribly expensive on memory.

Please note, I don't need a comparison of the gems. This series did a great job here: http://www.sitepoint.com/series/comparing-ruby-background-processing-libraries/

james
  • 3,989
  • 8
  • 47
  • 102

3 Answers3

7

Parallelism. You can have N workers sending emails in parallel. With rake you have a single thread, sending many emails will take a while.

Mike Perham
  • 21,300
  • 6
  • 59
  • 61
  • Yes well time isn't super important since it's already asynchronous, and honestly I don't have that many emails. Quick thought, the spinning up of a new environment isn't a big problem with the rake approach? – james Jul 07 '14 at 18:10
2

Also another huge difference that was a break for me was that rake task in background runs off the same Heroku dyno, but the other add-ons require you to have a separate worker dyno.

EDIT, in case anyone is googling, just learned that in Sidekiq you can use the same worker dyno, see this tutorial: https://coderwall.com/p/fprnhg

james
  • 3,989
  • 8
  • 47
  • 102
1

Another big difference might be the tools a gem like sidekiq gives you to handle the background jobs.

For example, if you need to process a scheduled background job to, say, read multiple CSV files every day, maybe you need to handle or at least see the outcome of that processing, read metrics, retry in case of failure, etc. I guess you would have to write that yourself with a rake task.

In my case (i got here googling), i need one very simple and not so heavy task to be done scheduled and asynchronous, so i'm going with a rake task and i save myself of going through installing, configuring and maintaining a gem like sidekiq (easy as it might be) with its dependencies on the server.

jomar
  • 103
  • 3
  • 6