How do you run a Helper / Controller method using Clockwork?

402 views Asked by At

I'm sure I've got the completely wrong of the stick with regard to how Clockwork works. Basically I'm got a number of methods that exist within a Controller, as they're currently triggered by navigating to their relevant routes. I'm trying to get clockwork to run these methods, but I get a number of errors, including No Method Errors.

I've had a look around but can't seem to find anything to point me in the right direction. If this isn't the way to do it, where do I need to put my action logic in order to execute it using Clockwork?

This is my clock.rb file at the moment, which results in a NoMethodError

require 'clockwork'
require './config/boot'
require './config/environment'

include Clockwork

handler do |job|
  puts "Running #{job}"
end

every(3.minutes, 'application.tester') { ApplicationController::tester }
1

There are 1 answers

0
TheIrishGuy On

This is horrible OO practice, let Rails call controller methods. Whatever code you have in these controller methods move to its own class or module and call them in a Rake task. Then proceed to call that rake task in Clockwork.