Class: CurationConcerns::Operation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/curation_concerns/operation.rb

Constant Summary collapse

PENDING =
'pending'.freeze
PERFORMING =
'performing'.freeze
FAILURE =
'failure'.freeze
SUCCESS =
'success'.freeze

Instance Method Summary collapse

Instance Method Details

#fail!(message = nil) ⇒ Object



29
30
31
32
33
34
# File 'app/models/curation_concerns/operation.rb', line 29

def fail!(message = nil)
  run_callbacks :failure do
    update(status: FAILURE, message: message)
    parent.rollup_status if parent
  end
end

#pending_job(job) ⇒ Object



40
41
42
# File 'app/models/curation_concerns/operation.rb', line 40

def pending_job(job)
  update(job_class: job.class.to_s, job_id: job.job_id, status: CurationConcerns::Operation::PENDING)
end

#performing!Object



36
37
38
# File 'app/models/curation_concerns/operation.rb', line 36

def performing!
  update(status: PERFORMING)
end

#rollup_statusObject

If this is a batch job (has children), check to see if all the children are complete



13
14
15
16
17
18
19
20
# File 'app/models/curation_concerns/operation.rb', line 13

def rollup_status
  with_lock do
    stats = children.pluck(:status)
    return if stats.include?(PENDING) || stats.include?(PERFORMING)
    return fail! if stats.include?(FAILURE)
    success!
  end
end

#success!Object



22
23
24
25
26
27
# File 'app/models/curation_concerns/operation.rb', line 22

def success!
  run_callbacks :success do
    update(status: SUCCESS)
    parent.rollup_status if parent
  end
end