Class: Sidekiq::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/api.rb

Overview

Encapsulates a pending job within a Sidekiq queue or sorted set.

The job should be considered immutable but may be removed from the queue via Job#delete.

Direct Known Subclasses

SortedEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, queue_name = nil) ⇒ Job

Returns a new instance of Job.



159
160
161
162
163
# File 'lib/sidekiq/api.rb', line 159

def initialize(item, queue_name=nil)
  @value = item
  @item = Sidekiq.load_json(item)
  @queue = queue_name || @item['queue']
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



157
158
159
# File 'lib/sidekiq/api.rb', line 157

def item
  @item
end

Instance Method Details

#[](name) ⇒ Object



198
199
200
# File 'lib/sidekiq/api.rb', line 198

def [](name)
  @item.send(:[], name)
end

#argsObject



169
170
171
# File 'lib/sidekiq/api.rb', line 169

def args
  @item['args']
end

#deleteObject

Remove this job from the queue.



191
192
193
194
195
196
# File 'lib/sidekiq/api.rb', line 191

def delete
  count = Sidekiq.redis do |conn|
    conn.lrem("queue:#{@queue}", 0, @value)
  end
  count != 0
end

#enqueued_atObject



177
178
179
# File 'lib/sidekiq/api.rb', line 177

def enqueued_at
  Time.at(@item['enqueued_at'] || 0)
end

#jidObject



173
174
175
# File 'lib/sidekiq/api.rb', line 173

def jid
  @item['jid']
end

#klassObject



165
166
167
# File 'lib/sidekiq/api.rb', line 165

def klass
  @item['class']
end

#latencyObject



185
186
187
# File 'lib/sidekiq/api.rb', line 185

def latency
  Time.now.to_f - @item['enqueued_at']
end

#queueObject



181
182
183
# File 'lib/sidekiq/api.rb', line 181

def queue
  @queue
end