Class: Rjob::Job
- Inherits:
-
Object
- Object
- Rjob::Job
- Defined in:
- lib/rjob/job.rb
Constant Summary collapse
- DeserializationError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#retry_num ⇒ Object
Returns the value of attribute retry_num.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(context) ⇒ Job
constructor
A new instance of Job.
- #serialize ⇒ Object
- #worker_args ⇒ Object
- #worker_class ⇒ Object
- #worker_class_name ⇒ Object
Constructor Details
#initialize(context) ⇒ Job
Returns a new instance of Job.
11 12 13 |
# File 'lib/rjob/job.rb', line 11 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/rjob/job.rb', line 9 def context @context end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/rjob/job.rb', line 6 def id @id end |
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/rjob/job.rb', line 8 def payload @payload end |
#retry_num ⇒ Object
Returns the value of attribute retry_num.
7 8 9 |
# File 'lib/rjob/job.rb', line 7 def retry_num @retry_num end |
Class Method Details
.deserialize(context, job_str) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rjob/job.rb', line 36 def self.deserialize(context, job_str) first = job_str.index('!') second = job_str.index('!', first + 1) if first == nil || second == nil raise DeserializationError.new("Malformed job string: '#{job_str}'") end begin new(context).tap do |job| job.id = job_str[0...first] job.retry_num = job_str[(first + 1)...second].to_i job.payload = job_str[(second + 1)..-1] end rescue MessagePack::MalformedFormatError => e raise DeserializationError.new("Malformed job msgpack payload: #{e.}") end end |
Instance Method Details
#serialize ⇒ Object
32 33 34 |
# File 'lib/rjob/job.rb', line 32 def serialize "#{@id}!#{@retry_num}!#{@payload}".b end |
#worker_args ⇒ Object
23 24 25 |
# File 'lib/rjob/job.rb', line 23 def worker_args @deserialized_payload[1] end |
#worker_class ⇒ Object
19 20 21 |
# File 'lib/rjob/job.rb', line 19 def worker_class @context.fetch_worker_class(class_name: worker_class_name) end |
#worker_class_name ⇒ Object
15 16 17 |
# File 'lib/rjob/job.rb', line 15 def worker_class_name @deserialized_payload[0] end |