Sidekiq: How can I get the execution time for a given job?

Created on 30 Aug 2016  Â·  3Comments  Â·  Source: mperham/sidekiq

MyWorker.perform_at(25.hours.from_now)
=> "80b6947a4180f19ec6119d3d" 

Sidekiq::Queue.new.find_job(_)
=>#<Sidekiq::Job:0x007f7f7cf01ad8...

The only dates that I can get is when the job was enqueued or created

{ .. "jid"=>"80b6947a4180f19ec6119d3d", "created_at"=>1472496977.644088, "enqueued_at"=>1472496977.64412},

I tried to dump all redis keys but I got some kind of issues and I couldn't get the execution time...
I was looking into this file: lib/sidekiq/worker.rb

      def perform_in(interval, *args)
        int = interval.to_f
        now = Time.now
        ts = (int < 1_000_000_000 ? (now + interval).to_f : int)

        item = { 'class' => self, 'args' => args, 'at' => ts }

        # Optimization to enqueue something now that is scheduled to go out now or in the past
        item.delete('at'.freeze) if ts <= now.to_f

        client_push(item)
      end

Is there any way to get this "at" field when I look for a record?

Thanks

Most helpful comment

https://github.com/mperham/sidekiq/wiki/API#scheduled

Sidekiq::ScheduledSet.new.each do |job|
  puts job.at
end

All 3 comments

Iterate through the scheduled set. Normal jobs don't have an at property because they aren't scheduled.

On Aug 30, 2016, at 10:11, Bernardo Castro [email protected] wrote:

MyWorker.perform_at(25.hours.from_now)
=> "80b6947a4180f19ec6119d3d"

Sidekiq::Queue.new.find_job(_)
=>#Job:0x007f7f7cf01ad8...

The only dates that I can get is when the job was enqueued or created

{ .. "jid"=>"80b6947a4180f19ec6119d3d", "created_at"=>1472496977.644088, "enqueued_at"=>1472496977.64412},

I tried to dump all redis keys but I got some kind of issues and I couldn't get the execution time...
I was looking into this file: lib/sidekiq/worker.rb

  def perform_in(interval, *args)
    int = interval.to_f
    now = Time.now
    ts = (int < 1_000_000_000 ? (now + interval).to_f : int)

    item = { 'class' => self, 'args' => args, 'at' => ts }

    # Optimization to enqueue something now that is scheduled to go out now or in the past
    item.delete('at'.freeze) if ts <= now.to_f

    client_push(item)
  end

Is there any way to get this "at" field when I look for a record?

Thanks

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

https://github.com/mperham/sidekiq/wiki/API#scheduled

Sidekiq::ScheduledSet.new.each do |job|
  puts job.at
end

@mperham thanks, I was enqueuing the job in a custom queue instead of using the scheduled set.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fatcatt316 picture fatcatt316  Â·  4Comments

homanchou picture homanchou  Â·  3Comments

mperham picture mperham  Â·  3Comments

davidcelis picture davidcelis  Â·  3Comments

rajcybage picture rajcybage  Â·  3Comments