Module: Chore::Job

Extended by:
Util
Defined in:
lib/chore/job.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods Classes: RejectMessageException

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

constantize, procline

Class Method Details

.decode(data) ⇒ Object



35
36
37
# File 'lib/chore/job.rb', line 35

def self.decode(data)
  Encoder::JsonEncoder.decode(data)
end

.included(base) ⇒ Object

:nodoc:



24
25
26
27
28
29
# File 'lib/chore/job.rb', line 24

def self.included(base) #:nodoc:
  @classes ||= []
  @classes << base.name
  base.extend(ClassMethods)
  base.extend(Hooks)
end

.job_classesObject

:nodoc:



20
21
22
# File 'lib/chore/job.rb', line 20

def self.job_classes #:nodoc:
  @classes || []
end

.payload(message) ⇒ Object



39
40
41
# File 'lib/chore/job.rb', line 39

def self.payload(message)
  message['args']
end

.payload_class(message) ⇒ Object



31
32
33
# File 'lib/chore/job.rb', line 31

def self.payload_class(message)
  constantize(message['class'])
end

Instance Method Details

#initialize(args = nil) ⇒ Object

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.



135
136
# File 'lib/chore/job.rb', line 135

def initialize(args=nil)
end

#perform(*args) ⇒ Object

This needs to be overriden by the object that is including this module.

Raises:

  • (NotImplementedError)


139
140
141
# File 'lib/chore/job.rb', line 139

def perform(*args)
  raise NotImplementedError
end

#perform_async(*args) ⇒ Object

Use the current configured publisher to send this job into a queue.



144
145
146
147
148
149
# 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]
  @chore_publisher.publish(self.class.prefixed_queue_name,self.class.job_hash(args))
  self.class.run_hooks_for(:after_publish,*args)
end