ruby-on-rails – 如何使用Clockwork Rails调度程序Gem?
发布时间:2020-12-17 03:04:15 所属栏目:百科 来源:网络整理
导读:我遇到了Clockwork调度程序进程的语法问题.我实际上遇到的问题与此主题中讨论的问题类似,但从未完全回答( How do I use Rails clockwork gem to run rake tasks?) 当我使用’heroku rake send_notifications’测试时,我的’scheduler.rake’正常工作.我的clo
我遇到了Clockwork调度程序进程的语法问题.我实际上遇到的问题与此主题中讨论的问题类似,但从未完全回答(
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) 有谁知道这两种方法的正确语法是什么? 解决方法
This answer works,但是你需要完全遵循它的字符串语法.所以在你的情况下:
every(30.seconds,'Send Notifications') { `rake scheduler:send_notifications` } 这意味着确保使用“`来包装rake任务,而不是”,因为这会让一些人绊倒. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |