0

I am building a webapp using ruby on rails that requires running C++ exe programs in the background. I compared 3 most frequently used gems for this(Delayed_Jobs, Resque, Sidekiq) and found that resque is the most suitable for me.

In Countroller I have create method like this

    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

In Worker class I have

    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

Now my question is how should I detect that job has finished? I want to send gemerated image file to client once images are generated by C++ application. which usercan view/download.

As redirect_to model_path(@model.id) will return after Resque.enqueue(JobWorker, @model.file.url) in the create in controller.

I tried using resque-status but that requires polling in the controller to check the status like...

    while status = Resque::Plugins::Status::Hash.get(job_id) and !status.completed? && !status.failed?
      sleep 1
      puts status.inspect
    end

Any suggestions?? Thank you in Advance...

4

1 回答 1

1

如果你想像 faye(http://faye.jcoglan.com/ruby.html)这样的异步系统,那么你可以在处理完成后向前端发送消息。编写代码以在系统代码完成执行后发布消息。

另一个简单的步骤(尽管对您来说可能不可行)是在流程结束时发送电子邮件。您可以向客户发送一封电子邮件,让他们知道“该过程已完成访问链接以查看结果”。

于 2015-02-26T21:26:12.433 回答