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:
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With