Class: Ddr::Batch::Batch

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ddr/batch/batch.rb

Constant Summary collapse

OUTCOME_SUCCESS =
"SUCCESS"
OUTCOME_FAILURE =
"FAILURE"
STATUS_READY =
"READY"
STATUS_VALIDATING =
"VALIDATING"
STATUS_INVALID =
"INVALID"
STATUS_VALIDATED =
"VALIDATED"
STATUS_QUEUED =
"QUEUED"
STATUS_PROCESSING =
"PROCESSING"
STATUS_RUNNING =
"RUNNING"
STATUS_FINISHED =
"FINISHED"
STATUS_INTERRUPTED =
"INTERRUPTED"
STATUS_RESTARTABLE =
"INTERRUPTED - RESTARTABLE"

Instance Method Summary collapse

Instance Method Details

#add_found_pid(pid, model) ⇒ Object



54
55
56
# File 'app/models/ddr/batch/batch.rb', line 54

def add_found_pid(pid, model)
  @found_pids[pid] = model
end

#collect_pre_assigned_pidsObject



62
63
64
# File 'app/models/ddr/batch/batch.rb', line 62

def collect_pre_assigned_pids
  batch_objects.map{ |x| x.pid if x.pid.present? }.compact
end

#completed_countObject



37
38
39
# File 'app/models/ddr/batch/batch.rb', line 37

def completed_count
  batch_objects.where(verified: true).count
end

#finished?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/ddr/batch/batch.rb', line 66

def finished?
  status == STATUS_FINISHED
end

#found_pidsObject



50
51
52
# File 'app/models/ddr/batch/batch.rb', line 50

def found_pids
  @found_pids ||= {}
end

#pre_assigned_pidsObject



58
59
60
# File 'app/models/ddr/batch/batch.rb', line 58

def pre_assigned_pids
  @pre_assigned_pids ||= collect_pre_assigned_pids
end

#time_to_completeObject



41
42
43
44
45
46
47
48
# File 'app/models/ddr/batch/batch.rb', line 41

def time_to_complete
  unless processing_step_start.nil?
    if completed_count > 0
      completed = completed_count
      ((Time.now - processing_step_start.to_time) / completed) * (batch_objects.count - completed)
    end
  end
end

#validateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/ddr/batch/batch.rb', line 23

def validate
  errors = []
  begin
    batch_objects.each do |object|
      unless object.verified
        errors << object.validate
      end
    end
  rescue Exception => e
    errors << "Exception raised during batch validation: #{e.backtrace}"
  end
  errors.flatten
end