简体   繁体   English

Ruby on Rails,延迟工作

[英]Ruby on Rails, delayed_job

I am using this gem for my application. 我正在为我的应用程序使用此gem I cannot find parameters that I need.I have two functions in my controller: create and analyse. 我找不到所需的参数。我的控制器中有两个功能:创建和分析。 I want to run an analyse-method after 5 min when a create-method was called or I have one more function in a model: process I want to run an anylse-method (from contoller) after 5 min when a process-method was called. 我想在调用创建analyse-method 5分钟后运行一种analyse-method ,或者我在模型中还有一个函数:进程我想在处理方法5分钟后运行一种anylse-method (来自anylse-method )叫。

I have found smt like this: 我发现这样的smt:

handle_asynchronously :in_the_future, :run_at => Proc.new { 5.minutes.from_now }

but it does not say after wich function it should be called. 但是它没有说在wich函数之后应该调用它。

edit: I attempted to delay my job and it seemed to save everything, the problem is that after 1 min it did not run a perform_analysis method. 编辑:我试图推迟工作,这似乎可以节省一切,问题是1分钟后它没有运行perform_analysis方法。 What can be the problem? 可能是什么问题?

model: 模型:

after_create :process_name, :perform_analysis

 def perform_analysis
   list=Analysis.do_picture_analyse
   update_image_url(list)

  end
 handle_asynchronously :perform_analysis, :run_at => Proc.new { 1.minutes.from_now }

SQL (8.3ms) INSERT INTO "delayed_jobs" ("attempts", "created_at", "failed_at", "handler", "last_error", "locked_at", "locked_by", "priority", "queue", "run_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["attempts", 0], ["created_at", Sat, 16 Mar 2013 14:30:19 UTC +00:00], ["failed_at", nil], ["handler", "--- !ruby/object:Delayed::PerformableMethod\\nobject: !ruby/ActiveRecord:Arraydb\\n attributes:\\n id: 45\\n arraydb_file_name: ND2_CD8_133A.CEL\\n arraydb_content_type: !binary |-\\n YXBwbGljYXRpb24vb2N0ZXQtc3RyZWFt\\n arraydb_file_size: 12110237\\n defined: 'yes'\\n patient: ND\\n tissue: CD8\\n stimulus: \\n chip_image: \\n chip_info: \\n user_id: \\n hist: \\n hist_RMA: \\n created_at: 2013-03-16 14:30:17.698742003 Z\\n updated_at: 2013-03-16 14:30:19.297934640 Z\\nmethod_name: :perform_analysis_without_delay\\nargs: []\\n"], ["last_error", nil], ["locked_at", nil], ["locked_by", nil], ["priority", 0], ["queue", nil], ["run_at", Sat, 16 Mar 2013 14:31:19 UTC +00:00], ["updated_at", Sat, SQL(8.3ms)插入“ delayed_jobs”(“尝试”,“ created_at”,“ failed_at”,“处理程序”,“ last_error”,“ locked_at”,“ locked_by”,“优先级”,“队列”,“ run_at” ,“ updated_at”)值(?,?,?,?,?,?,?,?,?,?,?)[[“ attempts”,0],[“ created_at”,2013年3月16日星期六14: 30:19 UTC +00:00],[“ failed_at”,nil],[“ handler”,“ ---!ruby / object:Delayed :: PerformableMethod \\ nobject:!ruby / ActiveRecord:Arraydb \\ n属性:\\ n id:45 \\ n arraydb_file_name:ND2_CD8_133A.CEL \\ n arraydb_content_type:!binary |-\\ n YXBwbGljYXRpb24vb2N0ZXQtc3RyZWFt \\ n arraydb_file_size:12110237 \\ n定义:'是\\\\ n组织:CD:\\ n患者:: ND chip_image:\\ n chip_info:\\ n用户ID:\\ n hist:\\ n hist_RMA:\\ n created_at:2013-03-16 14:30:17.698742003 Z \\ n Updated_at:2013-03-16 14:30:19.297934640 Z \\ nmethod_name ::perform_analysis_without_delay \\ nargs:[] \\ n“],[” last_error“,nil],[” locked_at“,nil],[” locked_by“,nil],[” priority“,0],[” queue“, nil],[“ run_at”,星期六,2013年3月16日14:31:19 UTC +00:00],[“ updated_at”,星期六, 16 Mar 2013 14:30:19 UTC +00:00]] 2013年3月16日14:30:19 UTC +00:00]]

Thanks in advance 提前致谢

You can use a callback to trigger the method. 您可以使用回调来触发该方法。 This will trigger the method :in_the_future to be queued up in the as a delayed job to run 5 min after the create action is complete. 这将触发方法:in_the_future在队列中排队,这是在创建操作完成后5分钟运行的延迟作业。

after_create :in_the_future

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM