Class: Woodhouse::Job

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/woodhouse/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name = nil, method = nil, args = nil) {|_self| ... } ⇒ Job

Returns a new instance of Job.

Yields:

  • (_self)

Yield Parameters:



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

#argumentsObject

Returns the value of attribute arguments.



5
6
7
# File 'lib/woodhouse/job.rb', line 5

def arguments
  @arguments
end

#job_methodObject

Returns the value of attribute job_method.



5
6
7
# File 'lib/woodhouse/job.rb', line 5

def job_method
  @job_method
end

#payloadObject

Returns the value of attribute payload.



5
6
7
# File 'lib/woodhouse/job.rb', line 5

def payload
  @payload
end

#worker_class_nameObject

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

#describeObject



64
65
66
# File 'lib/woodhouse/job.rb', line 64

def describe
  "#{worker_class_name}##{job_method}(#{arguments.inspect})"
end

#exchange_nameObject

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_idObject



68
69
70
# File 'lib/woodhouse/job.rb', line 68

def generate_id
  SecureRandom.hex(16)
end

#job_idObject



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_nameObject



60
61
62
# File 'lib/woodhouse/job.rb', line 60

def queue_name
  exchange_name
end

#to_hashObject



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