Class: Jobs::Base
- Inherits:
-
Object
- Object
- Jobs::Base
- Defined in:
- lib/jobs/base.rb
Instance Attribute Summary collapse
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(job_record, logger, lock) ⇒ Base
constructor
A new instance of Base.
-
#real_execute ⇒ Object
really run the execute method.
Constructor Details
#initialize(job_record, logger, lock) ⇒ Base
5 6 7 8 9 |
# File 'lib/jobs/base.rb', line 5 def initialize(job_record, logger, lock) @record = job_record @logger = logger @lock = lock end |
Instance Attribute Details
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
3 4 5 |
# File 'lib/jobs/base.rb', line 3 def lock @lock end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/jobs/base.rb', line 3 def logger @logger end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
3 4 5 |
# File 'lib/jobs/base.rb', line 3 def record @record end |
Instance Method Details
#execute ⇒ Object
11 12 |
# File 'lib/jobs/base.rb', line 11 def execute end |
#real_execute ⇒ Object
really run the execute method
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jobs/base.rb', line 15 def real_execute timer = Time.now res = execute @record.duration = Time.now - timer @record.status = res ? "complete" : "error" rescue Object => e # add error details to the record @record.details ||= "" @record.details << "#{e.message}\n#{e.backtrace.join("\n")}" # log the error @logger.error "#{e.message}\n#{e.backtrace.join("\n")}" @record.status = "error" ensure # it's no longer processing, so we must have landed here by error @record.status = 'error' if @record.status == 'processing' @record.locked = false @record.save end |