如何使用基于多模式的应用程序 Rails 设置延迟作业?

How to setup delayed jobs with multi schema based application Rails.?

你们能指导我如何让 rake jobs:work 在开发和生产环境中为多模式工作吗?提前致谢。

您可以在 Job class 中设置您的 schema

假设您有 CustomJob class。在此处设置您的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

中的上述作业
Delayed::Job.enqueue(CustomJob.new(object, method, args), queue: <queue>)

希望对您有所帮助。