I'm working on extrapolating an extensive background task to a sidekiq worker (first time working with sidekiq).
I've been able to get this to run correctly.
But I'm not sure how to check on the progress of the sidekiq worker - what's the best way to check to see if the worker is done with the perform_async function?
AutoWorker sidekiq task:
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
called from my controller:
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
Checkout the following extension gem to sidekiq: https://github.com/utgarda/sidekiq-status/blob/master/README.md
This is from the read me: