1
我正在將一個廣泛的後臺任務外推到sidekiq worker(第一次使用sidekiq)。Rails如何判斷sidekiq worker是否使用了perform_async
我已經能夠得到這個正確運行。
但我不知道如何檢查sidekiq worker的進度 - 檢查worker是否完成perform_async函數的最佳方法是什麼?
汽車工人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
從我的控制器稱爲:
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