Hi um quite new to rails platform and um looking for a rails cron job scheduling tutorials . I ve gone through with tutorials use whenever and the other scheduling gems , but um looking for a core ruby implementation with the cron tab on rails . Thank you in advance
-
1cron is cron, nothing related with rails. – xdazz Jun 18 '13 at 09:01
-
1Hey you can schedule cron jobs within rails app. Use "whenever" gem. its a simple and good gem. See my answer. It may help you. I am using the same gem in my application. – Jyothu Jun 18 '13 at 09:30
-
@xdazz yah cron is cron question was asked for an implementation in ruby – not 0x12 Jan 10 '18 at 20:36
6 Answers
Railscasts has a decent tutorial on using Cron.
EDIT
If you would like an example of how it was implemented from scratch, you could have a look at how the Whenever Gem is implemented here

- 1,785
- 3
- 25
- 43
-
1
-
1Ok well I suppose you could look at the source code (https://github.com/javan/whenever) for the Whenever gem, and that might give you a good starting point seeing as it's doing what you want to do from scratch... – TangoKilo Jun 18 '13 at 09:44
-
1No problem, I've edited the answer to better reflect what the original question was – TangoKilo Jun 18 '13 at 09:53
Many people are against this approach (see this SO thread) but triggering your application's action with curl/wget from a cron job may be a quick-and-easy solution for periodic tasks.
You just have to keep a few things in mind:
- Keep execution time of your action low (as it will block your application just like a regular web request would do)
- Make sure that you do not allow anyone to trigger the action (by using IP restrictions, secret tokens or other security measures)
For more information on this topic, I have written an article about it.

- 1
- 1

- 1,813
- 17
- 15
For minimal setup of "cron-like" tasks in "core" rails/ruby, I created https://github.com/Ebbe/arask
No need to install anything (other than the gem) or setup anything outside of rails.
Add gem 'arask'
to your Gemfile, run bundle install
, rails generate arask:install
and rails db:migrate
.
Now you can setup your tasks in the file config/initializers/arask.rb:
arask.create task: 'send:logs', cron: '0 2 * * *' # At 02:00 every day
arask.create script: 'puts "IM ALIVE!"', interval: :daily
arask.create task: 'my:awesome_task', interval: :hourly
arask.create task: 'my:other_awesome_task', interval: 2.hours
The tasks will automatically run if the server is running.

- 309
- 1
- 10
I'm using rufus-scheduler
, It uses threads to execute functions scheduled. Very simple to configure. just 3 steps:
1 - Add gem gem 'rufus-scheduler', '~> 3.6'
2 - Create file config/initializers/scheduler.rb
3 - Programming schedule in scheduler.rb:
require 'rufus-scheduler'
s = Rufus::Scheduler.singleton
s.every '5s' do
#do every 5 seconds exec this code
puts "WOWWWWWWWWWWWWWWWWWWWW"
end
s.in '2d' do
# every 2 days exec this
puts "Now it's me"
end
For more doubts : https://github.com/jmettraux/rufus-scheduler

- 2,369
- 1
- 27
- 37
-
1Good solution. Just one annotation, `scheduler` should be updated with `s` in line 8. – Alberto Crespo Oct 07 '19 at 16:14
-
1thanks dude! I did not notice this. thank you very much for up vote! – Darlan Dieterich Oct 07 '19 at 18:10
You can also use and external free service to outsource cronjobs http://guardiano.getpeople.in
DISCLAIMER: I made it

- 450
- 5
- 8