Class: Woodhouse::Job
- Inherits:
-
Object
- Object
- Woodhouse::Job
- Extended by:
- Forwardable
- Defined in:
- lib/woodhouse/job.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#job_method ⇒ Object
Returns the value of attribute job_method.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#worker_class_name ⇒ Object
Returns the value of attribute worker_class_name.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #describe ⇒ Object
-
#exchange_name ⇒ Object
TODO: copypasted from Woodhouse::Layout::Worker.
- #generate_id ⇒ Object
-
#initialize(class_name = nil, method = nil, args = nil) {|_self| ... } ⇒ Job
constructor
A new instance of Job.
- #job_id ⇒ Object
- #maybe(meth, *args, &blk) ⇒ Object
- #queue_name ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(class_name = nil, method = nil, args = nil) {|_self| ... } ⇒ Job
Returns a new instance of Job.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/woodhouse/job.rb', line 10 def initialize(class_name = nil, method = nil, args = nil) self.worker_class_name = class_name self.job_method = method self.arguments = args unless arguments["_id"] arguments["_id"] = generate_id end if arguments["payload"] self.payload = arguments.delete("payload") end yield self if block_given? end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/woodhouse/job.rb', line 5 def arguments @arguments end |
#job_method ⇒ Object
Returns the value of attribute job_method.
5 6 7 |
# File 'lib/woodhouse/job.rb', line 5 def job_method @job_method end |
#payload ⇒ Object
Returns the value of attribute payload.
5 6 7 |
# File 'lib/woodhouse/job.rb', line 5 def payload @payload end |
#worker_class_name ⇒ Object
Returns the value of attribute worker_class_name.
5 6 7 |
# File 'lib/woodhouse/job.rb', line 5 def worker_class_name @worker_class_name end |
Instance Method Details
#[](key) ⇒ Object
45 46 47 |
# File 'lib/woodhouse/job.rb', line 45 def [](key) arguments[key.to_s] end |
#describe ⇒ Object
64 65 66 |
# File 'lib/woodhouse/job.rb', line 64 def describe "#{worker_class_name}##{job_method}(#{arguments.inspect})" end |
#exchange_name ⇒ Object
TODO: copypasted from Woodhouse::Layout::Worker. Fix that
56 57 58 |
# File 'lib/woodhouse/job.rb', line 56 def exchange_name "#{worker_class_name}_#{job_method}".downcase end |
#generate_id ⇒ Object
68 69 70 |
# File 'lib/woodhouse/job.rb', line 68 def generate_id SecureRandom.hex(16) end |
#job_id ⇒ Object
23 24 25 |
# File 'lib/woodhouse/job.rb', line 23 def job_id arguments["_id"] end |
#maybe(meth, *args, &blk) ⇒ Object
49 50 51 52 53 |
# File 'lib/woodhouse/job.rb', line 49 def maybe(meth, *args, &blk) if respond_to?(meth) send(meth, *args, &blk) end end |
#queue_name ⇒ Object
60 61 62 |
# File 'lib/woodhouse/job.rb', line 60 def queue_name exchange_name end |
#to_hash ⇒ Object
27 28 29 30 31 32 |
# File 'lib/woodhouse/job.rb', line 27 def to_hash { "worker_class_name" => worker_class_name, "job_method" => job_method, }.merge(arguments) end |