我正在构建一个使用rails的the应用程序,它需要在后台运行C++ exe程序。我比较了三个最常用的宝石(Delayed_Jobs,Resque,Sidekiq),发现resque最适合我。
在财务总监中,我创建了这样的方法
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++应用程序生成图像时,我应该如何检测作业已经完成?,我想在C++应用程序生成图像后向客户端发送图像文件。哪个用户可以查看/下载。
redirect_to model_path(@model.id)将在create控制器中在Resque.enqueue(JobWorker,@model.file.url)之后返回。
我试过使用resque-status,但这需要控制器中的轮询来检查状态,比如.
while status = Resque::Plugins::Status::Hash.get(job_id) and !status.completed? && !status.failed?
sleep 1
puts status.inspect
end有什么建议吗?谢谢你提前..。
发布于 2015-02-26 21:26:12
如果您想要像faye(http://faye.jcoglan.com/ruby.html)这样的异步系统,那么您可以在流程完成时向前端发送一条消息。编写代码以在系统代码完成执行后发布消息。
另一个简单的步骤,虽然可能是不可行的,是在过程结束时发送一封电子邮件。您可以向客户发送电子邮件,让他们知道“该过程是完整的访问链接,以查看结果。”
https://stackoverflow.com/questions/28752587
复制相似问题