I'm trying to create a cron job that runs a controller method with the whenever gem but i'm having trouble.
config\schedule.rb
every 1.minutes do
runner "Reset.reset"
end
lib\reset.rb
class Reset
def reset
logger.debug("This is the cron job")
end
end
I also ran the whenever --update-crontab to update the cron job.
Why isn't the logger message showing up in the log?
Thanks for all the help.
That's because Reset.reset
trys to call the reset method on the Reset class. That is, Reset.reset
trys to call a class method.
Your reset method is an instance method. To define a Reset.reset
class method, use:
class Reset
def self.reset
logger.debug("This is the cron job")
end
end
Also, you'll need to make sure that you have a self.logger
class method as well, or that code will just die.
Lastly, for your own edification: Reset
as you have it written isn't a controller. It's just a plain old ruby object.