NotImplementedError 使用排队后端在未来排队作业
NotImplementedError Use a queueing backend to enqueue jobs in the future
我正在尝试使用 ActiveJob
对诸如电子邮件调度之类的作业进行排队,但我得到
NotImplementedError (Use a queueing backend to enqueue jobs in the future.
错误
更新提交到数据库后,在我的 model.rb
文件中
class Article < ActiveRecord::Base
include ActiveModel::Dirty
require './app/jobs/email_scheduler_job'
def send_approved_mail
if self.approved_was == false && self.approved
ArticleMailer.article_approved(self.owner).deliver_later
EmailSchedulerJob.set(wait: 2.weeks).perform_later(owner)
end
end
end
在我的 EmailSchedulerJob
class EmailSchedulerJob < ActiveJob::Base
queue_as :default
def perform(*args)
# Do something later
end
end
您以后需要使用队列适配器对作业进行排队。 Sidekiq is great in most cases, but it is quite complicated to set up. I think using sidekiq for email scheduling seems like an overkill. I would recommend using sucker_punch 为此。
要使用 sucker_punch 作为 ActiveJob 的适配器,请将其添加到您的 Gemfile 中:
gem 'sucker_punch'
然后配置后端使用sucker_punch:
# config/initializers/sucker_punch.rb
Rails.application.configure do
config.active_job.queue_adapter = :sucker_punch
end
您不需要创建发送电子邮件的作业。 ActionMailer 与 ActiveJob 集成在一起,因此 deliver_later 应该足够了。
希望对您有所帮助:)
我正在尝试使用 ActiveJob
对诸如电子邮件调度之类的作业进行排队,但我得到
NotImplementedError (Use a queueing backend to enqueue jobs in the future.
错误
更新提交到数据库后,在我的 model.rb
文件中
class Article < ActiveRecord::Base
include ActiveModel::Dirty
require './app/jobs/email_scheduler_job'
def send_approved_mail
if self.approved_was == false && self.approved
ArticleMailer.article_approved(self.owner).deliver_later
EmailSchedulerJob.set(wait: 2.weeks).perform_later(owner)
end
end
end
在我的 EmailSchedulerJob
class EmailSchedulerJob < ActiveJob::Base
queue_as :default
def perform(*args)
# Do something later
end
end
您以后需要使用队列适配器对作业进行排队。 Sidekiq is great in most cases, but it is quite complicated to set up. I think using sidekiq for email scheduling seems like an overkill. I would recommend using sucker_punch 为此。
要使用 sucker_punch 作为 ActiveJob 的适配器,请将其添加到您的 Gemfile 中:
gem 'sucker_punch'
然后配置后端使用sucker_punch:
# config/initializers/sucker_punch.rb
Rails.application.configure do
config.active_job.queue_adapter = :sucker_punch
end
您不需要创建发送电子邮件的作业。 ActionMailer 与 ActiveJob 集成在一起,因此 deliver_later 应该足够了。
希望对您有所帮助:)