No description, website, or topics provided.
Switch branches/tags
Nothing to show
Pull request Compare This branch is even with kgiszczak:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Crom is very simple scheduler for Rails.


Add this line to your Gemfile:

gem 'crom', :git => ''

and run:

bundle install

You can run crom generator now:

rails g crom:install

This command will create config/schedule.rb file where you can define your scheduled jobs. Sample file looks like this:

Crom.schedule do

  # every '1s' do
    # Some task
  # end

  # cron '* * * * *' do
    # Some task
  # end

  # schedule_in '20m' do
    # Some task
  # end

  # schedule_at 'Thu Mar 26 07:31:43 +0900 2020' do
    # Some task
  # end


You can run crom with rake command:

rake crom:start

This is helpful for debuging, or you can run crom as a daemon with:

./scrip/crom start

By default daemon is run with production environment. You can change this by passing -e flag:

./scrip/crom start -e development

Error Handler

You can define error handler like this:

Crom.handle_errors do |err|
  Mail.deliver do
    from    ''
    to      ''
    subject err.message
    body    err.backtrace.join("\n")

This handler will be called every time error occurs.

Using with Heroku

Only possible on cedar stack!

Create a file called Procfile in the root of your app and then add this line:

worker:  bundle exec rake crom:start

Heroku by default runs just one web process so you have to add extra worker process. Run this command on your command line:

heroku scale worker=1

and now you can check if processes are running:

heroku ps

you should see something like this:

web.1         up for 2m           bundle exec rails server -p $PORT
worker.1      up for 2m           bundle exec rake crom:start

Problems with installing gems on Heroku.

I went into problems with installing dependencies. I couldn't install latest version of daemons and rufus-scheduler gems. If you have this problem just add older versions of this gems to your Gemfile e.g.

gem 'daemons', '1.1.3'
gem 'rufus-scheduler', '2.0.9'