Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Daemon vs Runner vs Rake Tasks vs Active Job

I have a list of tasks that need to be performed in the background (Rails 5.0.1) in the following order-

  1. Download a zip file
  2. Extract the xml file from it (avg. size ~ 400 MB)
  3. Parse(Nokogiri XML::reader) the xml file for records that meet certain constraints and if found, add them to database (postgres)
  4. Retrieve some email addresses from database and send them email

This needs to be done everyday without any human input. Right now, I am using Rails runner to do all of that and scheduling it using cron ('Whenever' gem). So, is using 'runner' the right approach? Is there a less memory intensive approach I can use, given that the frontend (admin panel) won't be accessed much? How about active job, rake, daemons etc?

like image 542
rohank Avatar asked Sep 02 '25 09:09

rohank


1 Answers

. A rake task is just a bunch of code inside a namespace that is executed via rake management tool

. runner runs Ruby code in the context of Rails non-interactively

. Daemon on the other hand is completely different thing than this two, you can check more about it here: http://daemons.rubyforge.org/

For your case it's best to use rake because it doesn't boot rails "unless you make it" (runner have to boot rails).

Another thing is rake is single threaded, so If you want to a single task to be done efficiently you can use rake, if you have multiple tasks you can make use of workers and tools like Sidekiq, Resque and Delayed jobs

like image 108
amrdruid Avatar answered Sep 05 '25 00:09

amrdruid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!