Rails如何判断sidekiq工作者是否用perform_async完成

Tom*_*ond 4 ruby ruby-on-rails redis sidekiq

我正在将广泛的后台任务外推到sidekiq工作者(第一次使用sidekiq)。

我已经能够使其正常运行。

但是我不确定如何检查sidekiq工作程序的进度-检查工作程序是否已通过perform_async函数完成的最佳方法是什么?

AutoWorker sidekiq任务:

class AutoWorker
    include Sidekiq::Worker

    def perform(lead_id, cars)
        logger.info "WORKER CREATED"
        lead = Lead.find(lead_id)
        response = ZipCodeCheck.new(cars: cars, lead: lead).execute 
    end
end
Run Code Online (Sandbox Code Playgroud)

从我的控制器调用:

def update
    respond_to do |format|
      if @lead.update(lead_params)
          cars = params[:car_array]

          AutoWorker.perform_async(@lead.id, cars)
          format.json { render action: 'show', status: :created, location: @lead }
        else
          format.html { redirect_to @lead, notice: 'Lead was successfully updated.' }
          format.json { render action: 'show', status: :created, location: @lead}
        end
      else
        format.html { render action: 'edit' }
        format.json { render json: @lead.errors, status: :unprocessable_entity }
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

Tom*_*ast 7

将以下扩展gem检出到sidekiq:https : //github.com/utgarda/sidekiq-status/blob/master/README.md

这是从我读过的:

job_id = MyJob.perform_async(*args)
data = Sidekiq::Status::get_all job_id
data # => {status: 'complete', update_time: 1360006573, vino: 'veritas'}
Sidekiq::Status::get     job_id, :vino #=> 'veritas'
Sidekiq::Status::at      job_id #=> 5
Sidekiq::Status::total   job_id #=> 100
Sidekiq::Status::message job_id #=> "Almost done"
Run Code Online (Sandbox Code Playgroud)