延迟工作乘客生产未定义方法错误

发布于 2024-12-08 08:26:49 字数 349 浏览 0 评论 0原文

我正在使用延迟作业版本 2.1.4 和操作邮件程序 3.0.8 在后台发送电子邮件。

UserMailer.delay.newsletter(email)

它在开发和生产 Rails 控制台 方面与我配合得很好。

但是,当从我的现场生产乘客服务器调用它时,它会创建 DJ,但是当该 DJ 运行时,它会抛出

{undefined method `newsletter' for #<Class:0xc08afa0>

我认为问题

有帮助吗?

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 #<Class:0xc08afa0>

I think the problem

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写给空气的情书 2024-12-15 08:26:49

问题出在使用类方法的生产模式下的rails/passenger,

所以,我做了一个解决方案......我将尝试调用实例方法并避免调用<类方法。

让我们看一个例子;假设我需要在后台调用以下方法..

UserMailer.deliver_newsletter(email)

然后,我创建了一个新类 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 

并可以立即在后台运行该方法

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

因此,我现在正在后台运行一个 instance 方法,该方法将运行方法。

另一个例子..

假设我想运行

Product.list_all_by_user_and_category(user, category).delay

然后它可以通过

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

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
夜巴黎 2024-12-15 08:26:49

我的预感是,您在生产中有多个延迟作业版本。您是否使用捆绑器来启动延迟的作业流程?

我建议在在生产中进行捆绑安装时,我会使用 --binstubs 标志来生成一个包装器elasted_job 并使用该可执行文件来启动作业。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文