Search code examples
ruby-on-railscronactionmailer

How to write the cron job


I'm trying to set up cron job without using "Whenever" in development environment. I checked log and cron seems working in each 2 minutes but no mail was sent... How can I correctly write the cron job?

models/box.rb:

def self.reminder_mail
    @boxes = Box.all
    @boxes.each do |box|
      if box.status == "PENDING"
          NoticeMailer.sendmail_reminder(box).deliver
      end
    end
  end

Crontab

*/2 * * * *  ubuntu /home/ubuntu/workspace/box/reminder_mail 

cronlog

Feb 25 11:10:01 ubuntu-xenial CRON[4599]: (ubuntu) CMD (ubuntu /home/ubuntu/workspace/box/reminder_mail)
Feb 25 11:10:01 ubuntu-xenial CRON[4598]: (CRON) info (No MTA installed, discarding output)
Feb 25 11:12:01 ubuntu-xenial CRON[4605]: (ubuntu) CMD (ubuntu /home/ubuntu/workspace/box/reminder_mail)

Solution

  • I solved this problem! Important is to write rake PATH in my case /home/ubuntu/.rbenv/shims directly into PATH and not mention into cron job.

    */2 * * * * ubuntu cd /home/ubuntu/workspace/box && RAILS_ENV=development bundle exec rake reminder_task:reminder_mail >> /home/ubuntu/workspace/box/log/cron.log