Ruby on rails scheduled tasks

This is the first time I am planning a task, and I am not sure about the best implementation (or the correct implementation).

My goal: I have a ruby ​​on the settings of 4 rails with twilio and deployed to Heroku. I want the application to automatically send text messages to all my users once a week using a custom text message (which is recorded and created using information in the database).

From the research, I came to the following Gems: Whenever and Rufus-Scheduler .

I believe that both of these gems can get the job done, but after reading in Rufus' docs: "Please note: rufus-scheduler is not a replacement for cron." I'm stuck trying to figure out if what I really want is cron or "Rufus-Scheduler".

I still have the following questions: What is the cron job and when is the right time to use it? Why doesn't Rufus-Scheduler replace cron and what does it do differently? Which one should I use?

+6
source share
4 answers

rufus-scheduler is not a replacement for cron

can be expanded before "rufus-scheduler has never been written as a replacement for cron". The big message is "you are a developer, and as a developer you should know the environment that you inherit and the tools that it comes with. You need to know when to use them, when to simulate them, when to replace them."

Rufus-scheduler understands the syntax of "* * * * *" Cron. This made some people say, "rufus-scheduler is trying to replace Cron." It could be formulated as follows: "Some people abuse the rufus-planner instead of thinking (knowing) that the old faithful Kron would be better in this situation."

To become a good developer, you should seriously think about some sixadmin * nix skills, otherwise it will hurt to work. It can be as simple as "installing, starting, and managing a Linux box in VirtualBox on your system."

The rufus-scheduler schedule runs in the Ruby process. In the vanilla world, the rufus scheduler runs in the same Ruby process that serves HTTP requests (a Rails or Sinatra web application), and, oh, oops, schedules do not start when the application does not start.

Cron is a service provided by your * nix operating system. Other applications and services on your host rely on it. Cron reads its crontab and runs the script specified in it at the specified times. Thanks to a great time when Cron can run scripts in a Rails application.

This may interest you: https://devcenter.heroku.com/articles/clock-processes-ruby

+2
source

About Cron:

Cron is the name of a program that performs scheduled tasks on nix systems. that scheduled tasks in Windows, Cron does something similar for Linux at a conceptual level. Cron is one of the most useful tools on Linux or UNIX, such as operating systems. The cron (daemon) service runs in the background and constantly checks the / etc / crontab and / etc / cron. / Files. It also checks the directory / var / spool / cron /.

For schedule tasks on Heroku

The good news is that Heroku has a thing called Scheduler, which is an add-on to run tasks in your application at scheduled time intervals, just like cron in a traditional server environment. therefore, you really do not need to bother / play with cron or precious stones, as always. just use the Scheduler addon on Heroku.

For more information see: https://devcenter.heroku.com/articles/scheduler

+1
source

The cron task is a program that runs in an automatic schedule using cron software.

Rufus-Scheduler is different from cron because it works inside Ruby processes.

For what you describe, I believe that everything will be fine.

+1
source

whenever allows you to write ruby ​​code that will be converted to a crontab file, which is a file that defines the set of commands and the frequency for each command. This file is used by cron .

rufus-scheduler - pure ruby, you write ruby, and tasks are executed in ruby, for example, inside your application loop that calls scheduler.join , or in another thread that calls ruby your/rufus_scheduler_script.rb .

In my opinion, they do the same thing, with cron you use the linux command, but I do not see any other difference.

There are other options too , in my experience I had problems with rufus-scheduler and every time (they did not find classes in my Rails, but maybe it was just a fad), on the other hand, the clock mechanism worked for me.

0
source

All Articles