Class: DCA::Jobs::Job
- Inherits:
-
Object
- Object
- DCA::Jobs::Job
- Includes:
- Helpers::Logger
- Defined in:
- lib/dca/jobs/job.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
Add a job to queue.
- .perform(options = {}) ⇒ Object
- .queue ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ Job
constructor
A new instance of Job.
- #perform ⇒ Object
- #safe_perform! ⇒ Object
- #shutdown? ⇒ Boolean
Methods included from Helpers::Logger
Constructor Details
#initialize(options = {}) ⇒ Job
Returns a new instance of Job.
24 25 26 27 28 |
# File 'lib/dca/jobs/job.rb', line 24 def initialize( = {}) @options = trap('QUIT') { shutdown } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/dca/jobs/job.rb', line 7 def @options end |
Class Method Details
.create(options = {}) ⇒ Object
Add a job to queue. Queue name is a class module name
14 15 16 |
# File 'lib/dca/jobs/job.rb', line 14 def self.create(={}) Resque.enqueue(self, ) end |
.perform(options = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/dca/jobs/job.rb', line 18 def self.perform(={}) instance = new .symbolize_keys! instance.safe_perform! instance end |
.queue ⇒ Object
9 10 11 |
# File 'lib/dca/jobs/job.rb', line 9 def self.queue self.to_s.split("::")[-2] end |
Instance Method Details
#destroy ⇒ Object
47 48 49 |
# File 'lib/dca/jobs/job.rb', line 47 def destroy end |
#perform ⇒ Object
43 44 45 |
# File 'lib/dca/jobs/job.rb', line 43 def perform raise NotImplementedError end |
#safe_perform! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dca/jobs/job.rb', line 30 def safe_perform! perform on_success if respond_to?(:on_success) rescue Exception => exception if respond_to?(:on_failure) on_failure(exception) else raise exception end ensure destroy end |
#shutdown? ⇒ Boolean
51 52 53 |
# File 'lib/dca/jobs/job.rb', line 51 def shutdown? @shutdown end |