Ruby on Rails在后台工作〔resque+resque status〕
Ruby on Rails working in background [resque + resque-status]
我正在使用ruby on rails构建一个需要在后台运行C++exe程序的Web应用程序。我比较了3种最常用的宝石(Delayed_Jobs、Resque、Sidekiq),发现Resque最适合我
在Countroller中,我创建了这样的方法
def create
@model = Model.create(model_params)
# resque processe the file from the @model
Resque.enqueue(JobWorker, @model.file.url)
redirect_to model_path(@model.id)
end
在工人班,我有
class JobWorker
@queue = :file
def perform file_to_process
# calling time consuming C++ here which generates 2 image files.
system('my_file_processing_program "#{file_to_process}"')
end
end
现在我的问题是,我应该如何检测到作业已经完成我想在C++应用程序生成图像后将生成的图像文件发送到客户端。哪个用户可以查看/下载。
由于重定向到model_path(@model.id)将在创建控制器中的Resque.enqueue(JobWorker,@model.file.url)之后返回。
我尝试使用resque状态,但这需要在控制器中进行轮询以检查状态,如。。。
while status = Resque::Plugins::Status::Hash.get(job_id) and !status.completed? && !status.failed?
sleep 1
puts status.inspect
end
有什么建议吗??提前感谢。。。
如果你想使用像faye这样的异步系统(http://faye.jcoglan.com/ruby.html)因此,您可以在流程完成时向前端发送消息。编写代码以在系统代码完成执行后发布消息。
不过,另一个简单的步骤可能对你来说不可行,那就是在流程结束时发送一封电子邮件。您可以向客户发送一封电子邮件,让他们知道"流程已完成,请访问链接查看结果。"
相关文章:
- 我在C++中收到错误" [Error] ld returned 1 exit status".帮我解决这个问题
- 为什么错误"permission denied","id returned 1 exit status"仅在 IM 使用 C++ 中的头文件 fstream 时才出现
- wifi.status(),在AP_Mode运行时返回WL_Disconnected(6)
- 如何修复张量流中的"Non-OK-status: Not found: Op type not registered 'NoOp' in binary running"
- 在 c++ 和程序中使用循环遍历数组说"exit status -1"?
- 当常量引用参数绑定到右值时,右值是否保持其"status"?
- C++ status -1073741676
- 使用 procf//status 了解流程状态<pid>
- 代码块运行错误: "Process terminated with status -1073741510" 。我做错了什么?
- "Process terminated with status -1073741819" 带有矢量的简单程序
- Ruby on Rails在后台工作〔resque+resque status〕
- SigCgt 值未在 /proc/<pid>/status 文件中更新?
- Qt创建器中的"collect2: ld returned 1 exit status"
- "Id returned 1 exit status"错误 C++
- QueryPerformanceCounter Status?
- 正确读取/proc/pid/status的方法
- 编译时"collect2: error: ld returned 1 exit status"