开发者

Delayed Job passenger production undefined method error

I am using delayed job version 2.1.4 with action mailer 3.0.8 to send my emails in background.

UserMailer.delay.newsletter(email)

It works with me fine in development and production Rails console.

But when it is called from my live production passenger server, it creates DJ but when this DJ runs, it throws

{undefined method `newsletter' for #<C开发者_JAVA技巧lass:0xc08afa0>

I think the problem

Any help?


The problem is with rails/passenger in production mode with class methods

So, I made a work around solution... I will try to call instance method and avoid to call class method.

Lets see an example; assuming I need to call the following method in background..

UserMailer.deliver_newsletter(email)

Then, I created a new class DelayClassMethod

class DelayClassMethod
  def initialize(receiver_name, method_name, options={})
    @receiver_name = receiver_name
    @method_name = method_name
    @parameters = options[:params] || []
  end

  def perform
    eval(@receiver_name).send(@method_name, *@parameters)
  end
end 

and can run the method in background now by

DelayClassMethod.new("UserMailer", "deliver_newsletter", :params=>[email]).delay

So, I am running an instance method now in background which will run the class method.

Another example..

Assume I want to run

Product.list_all_by_user_and_category(user, category).delay

Then it can be run by

DelayClassMethod.new("Product", "list_all_by_user_and_category", :params => [user, category]).delay


My hunch is that you have multiple versions of the delayed_job in production. Are you using bundler to start your delayed job process?

I would recommend when doing bundle install in production, I would use the --binstubs flag to generate a wrapper around the delayed_job and use that executable to start the jobs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜