环境:
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将插入delayed_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 ...
控制台中的插入包含处理程序yaml中的“method_name :: tweet \ nargs:\ n- test tweet”,但从WEBrick执行时缺少该部分。
一些说明......