[英]Using models from a mounted Rails Engine in a Heroku Scheduler
我正在编写一个rake任务,用作Heroku Scheduler来从已安装的Rail引擎读取和修改某些模型。 引擎已在Rails应用程序本身中安装并运行良好(引擎本身位于独立的命名空间中)
我创建了一个rake任务,引用了引擎中的模型,当Heroku Scheduler运行该任务时,出现了“未初始化的常量”错误。 它可以很好地加载应用程序模型(即我在app / models /中定义的模型)。
我很欣赏Heroku Scheduler在启动时可能不会将安装的引擎中的模型添加到加载路径,但是我不确定明确告诉Scheduler加载这些模型的正确方法是什么。
我对Rails和安装Rails引擎有基本的了解,但显然不足以了解如何解决此问题。
如何在Heroku Scheduler运行的rake任务中包括已安装的引擎模型和应用程序模型?
编辑添加了Rakefile
这是我的Rakefile,尽管不会透露太多。 都是针对特定应用的模型:
require 'payments/worker' # in the Rails lib/ dir
task :handle_notifications do
# set the loggers to stdout for scheduled tasks
ActiveRecord::Base.logger = Logger.new(STDOUT)
Rails.logger = Logger.new(STDOUT)
worker = Worker.new
# Notification is the model defined in the engine
Notification.not_handled.each do |notification|
worker.handle! notification
end
end
所以我从Heroku Scheduler日志记录中获得了一个uninitialized constant Notification
IIRC,您必须通过指定在Rake任务中明确设置Rails环境
task :handle_notifications => :environment do
我认为这很简单
require 'your_engine_gem_name'
在您的Rakefile或需要引擎的任务中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.