Scheduler works once

207 Views Asked by At

The project uses the task scheduler - gem 'clockwork'. Capistrano executes the hook:

after :'deploy:finished', :'clockwork:restart'

The scheduler is triggered once (after this hook), runs all rake tasks, then tasks are not started. No matter how much I put an interval, in a day or 5 minutes, the task does not start anymore. Gem 'daemons' is installed. I will be glad to any help!

UPDATE

require 'clockwork'
require_relative './boot'
require_relative './environment'

module Clockwork
 handler do |job|
  puts "Running job: #{job}"
end

every(1.minute, 'job:some_task') do
 rake_task('job:some_task')
end

def rake_task(task_name)
  AppName::Application.load_tasks
  Rake::Task[task_name].invoke
end

configure do |config|
  config[:sleep_timeout] = 3600 # 1 hour
  config[:logger] = Logger.new("#{Rails.root}/log/clockwork.log")
  config[:tz] = 'UTC'
  config[:max_threads] = 15
  config[:thread] = true
end
end
1

There are 1 best solutions below

0
On

My guess is you're not running clockwork as a daemon, hence why it runs only once. Have a look at this gist

desc "Start clockwork"
task :start, :roles => clockwork_roles, :on_no_matching_servers => :continue do
  run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{log_file} --pidfile=#{pid_file} -D #{current_path} -- bundle exec clockwork config/clockwork.rb"
end

You could always SSH into your deployment and either check the list of PID or check in your rails application the temporal file that stores clockwork's PID:

.../tmp/pids/clockwork.pid

Alternatively check clockwork's logs:

.../log/clockwork.log