Search code examples
ruby-on-railscroncloud9-ide

Cron job not working for Whenever gem, rails 5


I am using ide cloud 9 Rails 5

I instaled gem whenever.

gem 'whenever', :require => false

schedule.rb:

set :output, "#{path}/log/cron.log"

every 2.minutes do
  rake "subscription:send_mails"
end


namespace :subscription do
  desc "Send dayly mails with new projects"
  task send_mails: :environment do

    Subscriber.where.not(categories: []).find_each do |subscriber|
      projects = Project.where(categories: subscriber.categories, created_at: 1.days.ago )
      SubscriptionMailer.send_email_with_new_projects(subscriber, projects).delivery_now
    end
  end
end

Run in command line:

bundle exec whenever
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /home/ubuntu/workspace && RAILS_ENV=production bundle exec rake subscription:send_mails --silent >> /home/ubuntu/workspace/log/cron.log 2>&1'

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.

Now running a local server in development mode. I don't see any evidence that the code is actually being run. log/cron.log is empty. Is there some step that I didn't do?


Solution

  • Cron jobs do not work on Cloud9 unless you're using an SSH workspace.


    Source: How to enable/run cron on Cloud9?