我遇到了Clockwork scheduler进程的语法问题。实际上,我遇到了与本文中讨论但从未完全回答的问题类似的问题(How do I use Rails clockwork gem to run rake tasks?)
当我用'heroku rake send_notifications‘测试我的'scheduler.rake’时,它工作正常。我的clock.rb进程也在工作,因为它将每30秒触发一次。然而,我遇到了时钟.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)有人知道这两种方法的正确语法是什么吗?
发布于 2015-03-30 14:54:25
但是,您需要严格遵循其字符串语法。,因此在您的示例中:
every(30.seconds, 'Send Notifications') {
`rake scheduler:send_notifications`
}这意味着一定要使用` `来包装rake任务,而不是" ",因为这会让一些人犯错。
发布于 2013-09-27 18:51:17
来自Hereko的关于实现时钟工作的文档可能会有所帮助
Scheduled Jobs and Custom Clock Processes in Ruby with Clockwork
https://stackoverflow.com/questions/13465869
复制相似问题