Delayed_job 3.0.0 在控制台中工作,但在 WEBrick 中不起作用
环境:
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 执行时该部分丢失。
一些注意事项...
- 我已经尝试过使用 .delay 和 handle_asynchronously 但都不起作用。
- 对于某些对象(例如 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...
- I've tried this with both .delay as well as handle_asynchronously but neither work.
- It does work with WEBrick for some objects, such as the Twitter::Client, but it doesn't work with my own models.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论