3

My application (in Rails) should provide two main tasks:

  • create activity (for example post to Twitter) in given time in the future
  • periodically crawler some site or download Tweets

I'm thinking about using DelayedJob gem or Whenever gem for cron tasks. Which is better in these situations?

Thanks for any advice.

kmaci
  • 3,094
  • 2
  • 18
  • 28

2 Answers2

4

create activity (for example post to Twitter) in given time in the future

If this is in response to an event/user action, then a background task would be ideal, as it's not a regular schedule. Ruby toolbox seems to be favouring Resque and Sidekiq over delayed job though, so have a look at those before settling.

periodically crawler some site or download Tweets

Converse to the above, if this is a regularly scheduled event then cron jobs are ideal. Nothing wrong with using whenever for this, but make sure you have some form of monitoring on the jobs to alert you if something goes wrong.

Matt
  • 13,948
  • 6
  • 44
  • 68
  • Ok, thanks. I should be able to use Redis for Sidekiq alongside my PosgreSQL database, shouldn't I? – kmaci Apr 04 '16 at 15:17
2

For creating the activity, I would definitely use a background job to do that (i.e. PostToTwitterJob). I have a preference for Sidekiq instead DelayedJob, as delayed_job does not seem to be active anymore. If you want the job to be performed at a specific time in the future, check out sidekiq's documentation.

As for the crawling, I would use both. Your crawler would be a background job (i.e. TweetsCrawlerJob), and you could launch it every hour with whenever.

born4new
  • 1,677
  • 12
  • 12
  • 1
    I want to clarify that `DelayedJob` is actively maintained here: https://github.com/collectiveidea/delayed_job. And as of Rails 5.2.1 it is still listed as an Active Job adapter: https://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html – chemturion Nov 20 '18 at 20:20