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.



1189
1190
1191
1192
1193
1194
# File 'lib/sidekiq/api.rb', line 1189

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



1227
1228
1229
# File 'lib/sidekiq/api.rb', line 1227

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

Instance Attribute Details

#process_idObject (readonly)

Returns the value of attribute process_id.



1186
1187
1188
# File 'lib/sidekiq/api.rb', line 1186

def process_id
  @process_id
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



1187
1188
1189
# File 'lib/sidekiq/api.rb', line 1187

def thread_id
  @thread_id
end

Instance Method Details

#[](key) ⇒ Object

deprecated



1213
1214
1215
1216
1217
1218
1219
# File 'lib/sidekiq/api.rb', line 1213

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



1204
1205
1206
# File 'lib/sidekiq/api.rb', line 1204

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

#payloadObject



1208
1209
1210
# File 'lib/sidekiq/api.rb', line 1208

def payload
  @hsh["payload"]
end

#queueObject



1196
1197
1198
# File 'lib/sidekiq/api.rb', line 1196

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:



1223
1224
1225
# File 'lib/sidekiq/api.rb', line 1223

def raw(name)
  @hsh[name]
end

#respond_to_missing?(name, *args) ⇒ Boolean

Returns:

  • (Boolean)


1231
1232
1233
# File 'lib/sidekiq/api.rb', line 1231

def respond_to_missing?(name, *args)
  @hsh.respond_to?(name)
end

#run_atObject



1200
1201
1202
# File 'lib/sidekiq/api.rb', line 1200

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