Delayed_job 3.0.0 在控制台中工作,但在 WEBrick 中不起作用

发布于 2024-12-29 09:23:12 字数 2500 浏览 0 评论 0原文

环境:

  Rails => 3.1.0
  delayed_job => 3.0.1
  delayed_job_active_record => 0.3.1
  WEBrick => 1.3.1
  ruby => 1.9.2

代码:

class Comment < ActiveRecord::Base
  def tweet(tweet_msg)
    client = Twitter::Client.new
    client.update(tweet_msg)
  end

  after_save :tweet_comment
  def tweet_comment
    self.delay.tweet('test tweet')
  end
end

控制台:

从控制台,我将以下内容插入到delayed_jobs 表中,并调用tweet_as_site 函数。一切工作正常......

  SQL (0.5ms)  INSERT INTO `delayed_jobs` (`attempts`, `created_at`, `failed_at`, `handler`, `last_error`, `locked_at`, `locked_by`, `priority`, `queue`, `run_at`, `updated_at`) VALUES (0, '2012-01-25 21:21:48', NULL, '--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/ActiveRecord:Comment\n attributes:\n id: 121\n title: \'\'\n comment: aa\n commentable_id: 2296\n commentable_type: Game\n user_id: 1\n created_at: 2012-01-25 21:19:19.000000000Z\n updated_at: 2012-01-25 21:19:19.000000000Z\nmethod_name: :tweet\nargs:\n- test tweet\n', NULL, NULL, NULL, 0, NULL, '2012-01-25 21:21:48', '2012-01-25 21:21:48')

Log:
  2012-01-25T13:21:52-0800: [Worker(delayed_job host:ubuntu pid:13063)] Comment#tweet completed after 1.6850
  2012-01-25T13:21:52-0800: [Worker(delayed_job host:ubuntu pid:13063)] 1 jobs processed at 0.5913 j/s, 0 failed ...

然后,当我通过 WEBrick 网络服务器执行此操作时,以下 sql 被插入到elasted_jobs表中......

  SQL (0.4ms)  INSERT INTO `delayed_jobs` (`attempts`, `created_at`, `failed_at`, `handler`, `last_error`, `locked_at`, `locked_by`, `priority`, `queue`, `run_at`, `updated_at`) VALUES (0, '2012-01-25 21:19:19', NULL, '--- !ruby/object:Delayed::PerformableMethod\nattributes:\n id: 121\n title: \'\'\n comment: aa\n commentable_id: 2296\n commentable_type: Game\n user_id: 1\n created_at: 2012-01-25 21:19:19.759253106Z\n updated_at: 2012-01-25 21:19:19.759253106Z\n', NULL, NULL, NULL, 0, NULL, '2012-01-25 21:19:19', '2012-01-25 21:19:19')
Log:
  2012-01-25T13:19:20-0800: [Worker(delayed_job host:ubuntu pid:13063)] NilClass# completed after 0.0083
  2012-01-25T13:19:20-0800: [Worker(delayed_job host:ubuntu pid:13063)] 1 jobs processed at 55.5559 j/s, 0 failed ...

来自控制台的插入包括“method_name: :tweet\nargs:\n- test tweet”处理程序 yaml,但是从 WEBrick 执行时该部分丢失。

一些注意事项...

  1. 我已经尝试过使用 .delay 和 handle_asynchronously 但都不起作用。
  2. 对于某些对象(例如 Twitter::Client),它确实可以与 WEBrick 一起使用,但它不适用于我自己的模型。

Environment:

  Rails => 3.1.0
  delayed_job => 3.0.1
  delayed_job_active_record => 0.3.1
  WEBrick => 1.3.1
  ruby => 1.9.2

Code:

class Comment < ActiveRecord::Base
  def tweet(tweet_msg)
    client = Twitter::Client.new
    client.update(tweet_msg)
  end

  after_save :tweet_comment
  def tweet_comment
    self.delay.tweet('test tweet')
  end
end

Console:

From the console I get the following inserted into the delayed_jobs table and the tweet_as_site function gets called. Everything works fine....

  SQL (0.5ms)  INSERT INTO `delayed_jobs` (`attempts`, `created_at`, `failed_at`, `handler`, `last_error`, `locked_at`, `locked_by`, `priority`, `queue`, `run_at`, `updated_at`) VALUES (0, '2012-01-25 21:21:48', NULL, '--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/ActiveRecord:Comment\n attributes:\n id: 121\n title: \'\'\n comment: aa\n commentable_id: 2296\n commentable_type: Game\n user_id: 1\n created_at: 2012-01-25 21:19:19.000000000Z\n updated_at: 2012-01-25 21:19:19.000000000Z\nmethod_name: :tweet\nargs:\n- test tweet\n', NULL, NULL, NULL, 0, NULL, '2012-01-25 21:21:48', '2012-01-25 21:21:48')

Log:
  2012-01-25T13:21:52-0800: [Worker(delayed_job host:ubuntu pid:13063)] Comment#tweet completed after 1.6850
  2012-01-25T13:21:52-0800: [Worker(delayed_job host:ubuntu pid:13063)] 1 jobs processed at 0.5913 j/s, 0 failed ...

Then when I do this through the WEBrick webserver, the following sql gets inserted into the delayed_jobs table...

  SQL (0.4ms)  INSERT INTO `delayed_jobs` (`attempts`, `created_at`, `failed_at`, `handler`, `last_error`, `locked_at`, `locked_by`, `priority`, `queue`, `run_at`, `updated_at`) VALUES (0, '2012-01-25 21:19:19', NULL, '--- !ruby/object:Delayed::PerformableMethod\nattributes:\n id: 121\n title: \'\'\n comment: aa\n commentable_id: 2296\n commentable_type: Game\n user_id: 1\n created_at: 2012-01-25 21:19:19.759253106Z\n updated_at: 2012-01-25 21:19:19.759253106Z\n', NULL, NULL, NULL, 0, NULL, '2012-01-25 21:19:19', '2012-01-25 21:19:19')
Log:
  2012-01-25T13:19:20-0800: [Worker(delayed_job host:ubuntu pid:13063)] NilClass# completed after 0.0083
  2012-01-25T13:19:20-0800: [Worker(delayed_job host:ubuntu pid:13063)] 1 jobs processed at 55.5559 j/s, 0 failed ...

The insert from the console includes "method_name: :tweet\nargs:\n- test tweet" in the handler yaml, but that part is missing when executed from WEBrick.

Some notes...

  1. I've tried this with both .delay as well as handle_asynchronously but neither work.
  2. It does work with WEBrick for some objects, such as the Twitter::Client, but it doesn't work with my own models.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文