mardi 15 mars 2016

job is running but sidekiq queue is empty

I am confused about how Sidekiq worker works and how I can access the status of the background job. If someone can explain in very plain words, it would be very helpful.

My problem is that my user submits a job and to check the status of the job I check the size of the queue and the status of the job.

class PagesWorker
    include Sidekiq::Worker
    include Sidekiq::Status::Worker

    def perform(ifile)
        system "rake ..."

        # What do the following do? In what scenario would I need to set these?
        total 100
        at 5, "Almost done"
        store vino: 'veritas'
        vino = retrieve :vino
    end
end

pages_controller:

def submit
    job_id = SomeWorker.perform_async(file)
    flash[:notice] = "#{job_id} is being processed."
end

def finished(job_id)
    queue = Sidekiq::Status.new('high')
    if Sidekiq::Status::complete? job_id == true || queue.size == 0
       flash[:success] = "#{job_id} is finished."
    elsif Sidekiq::Status::complete? job_id == false || queue.size > 0
       flash[:notice] = "#{job_id} is being processed.
    end
end

In myrailsapp/sidekiq page the number of processed jobs increments by one every time I submit a job, which is good. The queue is there but its size is always 0, which isn't correct. And there are no jobs listed in the queue, which again isn't correct.

However the job is being processed. Could the reason for the job not appearing in the sidekiq page be that the job finishes in less that a minute? Or maybe because the worker runs a system command to execute a rake?

I have also checked the following in the terminal, while the process is running:

Sidekiq::Status::complete? job_id #returns false
Sidekiq::Status::status(job_id) #returns nothing
Sidekiq::Status::get_all job_id #returns {"update_time"=>"1458063970", "total"=>"100", "at"=>"5", "message"=>"Almost done"}, and after a while returns {}

To sum up, my queue is empty, my jobs list is empty, but my job is running. How is this possible? What can I do to track the status of my job?

Aucun commentaire:

Enregistrer un commentaire