Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if whenever gem is working?

I've got the following configuration. I've installed whenever gem, created shedule.rb:

# Learn more: http://github.com/javan/whenever

every 6.hours do
    runner "Part.check_status_update"
end

In part.rb model I have corresponding method.

A. How can I check if whenever runs? As I understand it should only modify the crontab after whenever command in the bash, yes?

B. If the method is not triggered - then how can I debug the scheduled jobs? If I put into my method puts statements - where shall they be stored or outputted?

like image 518
zmii Avatar asked Jun 08 '15 21:06

zmii


People also ask

What is whenever gem?

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.

What is cron job in rails?

Cron is a job scheduling system available in Linux & MacOS operating systems. It can be used to run any program at any given time. This includes Ruby code! If there is a specific recurring task that you would like to run automatically every day, every week or even every hour, then Cron may be what you're looking for.


1 Answers

You need to define a log file, which will then receive any output from your Part.check_status_update call (such as puts calls). You can set a default log file for all of your jobs at the top of your schedule.rb file, such as:

set :output, '/path/to/file.log'

For example, to log to Rails.root/log/whenever.log:

set :output, 'log/whenever.log'

You can also define the output per-task:

runner "Part.check_status_update", :output => 'log/check_status_update.log'

See the Whenever wiki entry on the subject for a full explanation of details and options, such as logging errors to a separate file.

like image 111
Kimball Avatar answered Sep 19 '22 14:09

Kimball