你们能指导我如何允许rake作业:在开发和生产环境中为多模式工作吗。提前谢谢。

最佳答案

您可以在schema类中设置Job
假设你有CustomJob课。在此处设置您的schema

class CustomJob

  attr_accessor :object, :method_name, :args, :schema

  def initialize object, method_name, args
    @object = object
    @method_name = method_name
    @args = args
    @schema = ActiveRecord::Base.connection.schema_search_path
  end

  def perform
    object.send(method_name, *args) if object
  end

  def before(job)
    ActiveRecord::Base.connection.schema_search_path = schema
  end

  def after(job)
    ActiveRecord::Base.connection.schema_search_path = 'public'
  end

  def max_attempts
    return 2
  end

end

initialize上述工作
Delayed::Job.enqueue(CustomJob.new(object, method, args), queue: <queue>)

我希望这会有帮助。

关于ruby-on-rails - 如何使用基于多架构的应用程序Rails设置延迟的作业?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34509442/

10-11 03:31
查看更多