Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails how to tell if a sidekiq worker is done with perform_async

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
like image 664
Tom Hammond Avatar asked Oct 05 '15 01:10

Tom Hammond


1 Answers

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"
like image 164
Tom Fast Avatar answered Sep 30 '22 12:09

Tom Fast