module Chore::Job
Chore::Job
is the module which gives your job classes the methods they need to be published and run within Chore
. You cannot have a Job
in Chore
that does not include this module
Public Class Methods
decode(data)
click to toggle source
# File lib/chore/job.rb, line 35 def self.decode(data) Encoder::JsonEncoder.decode(data) end
new(args=nil)
click to toggle source
This is handy to override in an included job to be able to do job setup that requires access to a job’s arguments to be able to perform any context specific initialization that may be required.
# File lib/chore/job.rb, line 135 def initialize(args=nil) end
payload(message)
click to toggle source
# File lib/chore/job.rb, line 39 def self.payload(message) message['args'] end
payload_class(message)
click to toggle source
# File lib/chore/job.rb, line 31 def self.payload_class(message) constantize(message['class']) end
Public Instance Methods
perform(*args)
click to toggle source
This needs to be overriden by the object that is including this module.
# File lib/chore/job.rb, line 139 def perform(*args) raise NotImplementedError end
perform_async(*args)
click to toggle source
Use the current configured publisher to send this job into a queue.
# File lib/chore/job.rb, line 144 def perform_async(*args) self.class.run_hooks_for(:before_publish,*args) @chore_publisher ||= self.class.options[:publisher] publish_job_hash = self.class.job_hash(args) Chore.run_hooks_for(:around_publish, self.class.prefixed_queue_name, publish_job_hash) do @chore_publisher.publish(self.class.prefixed_queue_name,publish_job_hash) end self.class.run_hooks_for(:after_publish,*args) end