Class: Dunlop::ExecutionBatch

Inherits:
ApplicationRecord show all
Includes:
Loggable
Defined in:
app/models/dunlop/execution_batch.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#log_state_transition, #logger, #with_nested_logger, #with_nested_logger_and_catch_failed

Methods inherited from ApplicationRecord

truncate

Class Method Details

.batch_pid_idObject



26
27
28
# File 'app/models/dunlop/execution_batch.rb', line 26

def batch_pid_id
  :global
end

.cleanupObject



62
63
64
# File 'app/models/dunlop/execution_batch.rb', line 62

def cleanup
  where("created_at < ?", 1.month.ago).destroy_all
end

.exection_required?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/dunlop/execution_batch.rb', line 38

def exection_required?
  #updated_ats = [
  #  SourceFile.maximum(:updated_at),
  #  FunctionalConfiguration.maximum(:updated_at),
  #]

  #latest_batch_created_at = latest.try(:created_at) || 1.year.ago

  #!!updated_ats.detect do |updated_at|
  #  updated_at >= latest_batch_created_at
  #end
  true
end

.executeObject



52
53
54
55
56
57
58
59
60
# File 'app/models/dunlop/execution_batch.rb', line 52

def execute
  return if Dunlop::ExecutionBatchPid.new(:global).locked?
  batch = nil
  Dunlop::ExecutionBatchPid.new(batch_pid_id).lock do
    batch = create
    batch.execute_process
  end
  batch
end

.execute_if_requiredObject



34
35
36
# File 'app/models/dunlop/execution_batch.rb', line 34

def execute_if_required
  execute if exection_required?
end

.latestObject



30
31
32
# File 'app/models/dunlop/execution_batch.rb', line 30

def latest
  where(state: :completed).order(identifier: :desc).order(created_at: :desc).first
end

Instance Method Details

#execute_process(options = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/dunlop/execution_batch.rb', line 13

def execute_process(options={})
  with_nested_logger_and_catch_failed do
    processing!
    logger.benchmark { process_steps }
    completed!
  end
end

#process_stepsObject



21
22
23
# File 'app/models/dunlop/execution_batch.rb', line 21

def process_steps
  raise ImplementInSubclass.new(self)
end