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.


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

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


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

def item
  @item
end

Instance Method Details

#[](name) ⇒ Object


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

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

#argsObject


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

def args
  @item['args']
end

#deleteObject

Remove this job from the queue.


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

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

#jidObject


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

def jid
  @item['jid']
end

#klassObject


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

def klass
  @item['class']
end

#queueObject


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

def queue
  @queue
end