Sha256: 4555f324dd3fdfeb3df8d926b9cdc5dd22ea3d2fe86680b2fb5c7dcb28ebd0b7

Contents?: true

Size: 1.12 KB

Versions: 43

Compression:

Stored size: 1.12 KB

Contents

module CurationConcerns
  class Operation < ActiveRecord::Base
    PENDING = 'pending'.freeze
    PERFORMING = 'performing'.freeze
    FAILURE = 'failure'.freeze
    SUCCESS = 'success'.freeze

    acts_as_nested_set
    define_callbacks :success, :failure
    belongs_to :user, class_name: '::User'

    # If this is a batch job (has children), check to see if all the children are complete
    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

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

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

    def performing!
      update(status: PERFORMING)
    end

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

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
curation_concerns-1.3.2 app/models/curation_concerns/operation.rb
curation_concerns-1.3.1 app/models/curation_concerns/operation.rb
curation_concerns-1.3.0 app/models/curation_concerns/operation.rb
curation_concerns-1.2.0 app/models/curation_concerns/operation.rb
curation_concerns-1.1.2 app/models/curation_concerns/operation.rb
curation_concerns-1.1.1 app/models/curation_concerns/operation.rb
curation_concerns-1.1.0 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta10 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta9 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta8 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta7 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta6 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta5 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta4 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta3 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta2 app/models/curation_concerns/operation.rb
curation_concerns-1.0.0.beta1 app/models/curation_concerns/operation.rb
curation_concerns-0.14.0 app/models/curation_concerns/operation.rb
curation_concerns-0.14.0.pre4 app/models/curation_concerns/operation.rb