Class: Hyrax::Operation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hyrax::Operation
- Defined in:
- app/models/hyrax/operation.rb
Overview
The database storage of inter-related jobs and their states.
Direct Known Subclasses
Constant Summary collapse
- PENDING =
'pending'.freeze
- PERFORMING =
'performing'.freeze
- FAILURE =
'failure'.freeze
- SUCCESS =
'success'.freeze
Instance Method Summary collapse
-
#fail!(message = nil) ⇒ Object
Mark this operation as a FAILURE.
-
#pending_job(job) ⇒ Object
Sets the operation status to PENDING.
-
#performing! ⇒ Object
Sets the operation status to PERFORMING.
-
#rollup_status ⇒ Object
If this is a batch job (has children), check to see if all the children are complete.
-
#success! ⇒ Object
Mark this operation as a SUCCESS.
Instance Method Details
#fail!(message = nil) ⇒ Object
Where are these callbacks defined? Document this
This will run any registered :success callbacks
Mark this operation as a FAILURE. If this is a child operation, roll up to the parent any failures.
64 65 66 67 68 69 |
# File 'app/models/hyrax/operation.rb', line 64 def fail!( = nil) run_callbacks :failure do update(status: FAILURE, message: ) parent.rollup_status if parent end end |
#pending_job(job) ⇒ Object
Sets the operation status to PENDING
80 81 82 |
# File 'app/models/hyrax/operation.rb', line 80 def pending_job(job) update(job_class: job.class.to_s, job_id: job.job_id, status: Hyrax::Operation::PENDING) end |
#performing! ⇒ Object
Sets the operation status to PERFORMING
73 74 75 |
# File 'app/models/hyrax/operation.rb', line 73 def performing! update(status: PERFORMING) end |
#rollup_status ⇒ Object
If this is a batch job (has children), check to see if all the children are complete
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/hyrax/operation.rb', line 28 def rollup_status with_lock do # We don't need all of the status of the children, just need to see # if there is at least one PENDING, PERFORMING, or FAILURE. # With this change, it doesn't matter if we have 10_000 children or 1, we will only ever get # back an that is no longer than the total number of possible status values. Is it necessary? # No, but there is no need to instantiate an array of all of those values. stats = children.select(:status).distinct.pluck(:status) return if stats.include?(PENDING) || stats.include?(PERFORMING) return fail! if stats.include?(FAILURE) success! end end |
#success! ⇒ Object
Where are these callbacks defined? Document this
This will run any registered :success callbacks
Mark this operation as a SUCCESS. If this is a child operation, roll up to the parent any failures.
49 50 51 52 53 54 |
# File 'app/models/hyrax/operation.rb', line 49 def success! run_callbacks :success do update(status: SUCCESS) parent.rollup_status if parent end end |