Class: Sidekiq::Work

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

Overview

Sidekiq::Work represents a job which is currently executing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid, tid, hsh) ⇒ Work

Returns a new instance of Work.



1160
1161
1162
1163
1164
1165
# File 'lib/sidekiq/api.rb', line 1160

def initialize(pid, tid, hsh)
  @process_id = pid
  @thread_id = tid
  @hsh = hsh
  @job = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*all) ⇒ Object



1198
1199
1200
# File 'lib/sidekiq/api.rb', line 1198

def method_missing(*all)
  @hsh.send(*all)
end

Instance Attribute Details

#process_idObject (readonly)

Returns the value of attribute process_id.



1157
1158
1159
# File 'lib/sidekiq/api.rb', line 1157

def process_id
  @process_id
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



1158
1159
1160
# File 'lib/sidekiq/api.rb', line 1158

def thread_id
  @thread_id
end

Instance Method Details

#[](key) ⇒ Object

deprecated



1184
1185
1186
1187
1188
1189
1190
# File 'lib/sidekiq/api.rb', line 1184

def [](key)
  kwargs = {uplevel: 1}
  kwargs[:category] = :deprecated if RUBY_VERSION > "3.0" # TODO
  warn("Direct access to `Sidekiq::Work` attributes is deprecated, please use `#payload`, `#queue`, `#run_at` or `#job` instead", **kwargs)

  @hsh[key]
end

#jobObject



1175
1176
1177
# File 'lib/sidekiq/api.rb', line 1175

def job
  @job ||= Sidekiq::JobRecord.new(@hsh["payload"])
end

#payloadObject



1179
1180
1181
# File 'lib/sidekiq/api.rb', line 1179

def payload
  @hsh["payload"]
end

#queueObject



1167
1168
1169
# File 'lib/sidekiq/api.rb', line 1167

def queue
  @hsh["queue"]
end

#raw(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



1194
1195
1196
# File 'lib/sidekiq/api.rb', line 1194

def raw(name)
  @hsh[name]
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


1202
1203
1204
# File 'lib/sidekiq/api.rb', line 1202

def respond_to_missing?(name)
  @hsh.respond_to?(name)
end

#run_atObject



1171
1172
1173
# File 'lib/sidekiq/api.rb', line 1171

def run_at
  Time.at(@hsh["run_at"])
end