我在 Clockwork 调度程序进程的语法方面遇到问题。实际上,我遇到了与此线程中讨论的类似问题,但从未完全回答(如何使用 Rails Clockwork gem 运行 rake 任务? https://stackoverflow.com/questions/11513058/how-do-i-use-rails-clockwork-gem-to-run-rake-tasks)
当我使用“heroku rake send_notifications”测试时,我的“scheduler.rake”工作正常。我的clock.rb 进程也在工作,因为它每30 秒触发一次。但是,我在使用 Clock.rb 的语法来正确运行“rake.scheduler”中的“send_notifications”任务时遇到问题。它看起来是这样的:
# scheduler.rake
desc "This task is called by the Heroku scheduler add-on"
task :send_notifications => :environment do
puts "this test is working correctly!"
end
这是clock.rb 的样子:
require File.expand_path('../../config/boot', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'clockwork'
include Clockwork
every(30.seconds, 'Send notifications') {
# Heroku::API.new.post_ps('pocket-pal', 'rake scheduler:send_notifications')
rake scheduler:send_notifications
}
正如您所看到的,我尝试使用 Heroku API 并调用 rake 来使用独立的进程。
当我使用 Heroku API 时,出现以下错误:
ERROR -- : uninitialized constant Heroku (NameError)
当我调用 rake 时,出现以下错误:
ERROR -- : undefined local variable or method `send_notifications' for main:Object (NameError)
有谁知道这两种方法的正确语法是什么?