Class: CronoTrigger::ExecutionTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/crono_trigger/execution_tracker.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schedulable) ⇒ ExecutionTracker

Returns a new instance of ExecutionTracker.



3
4
5
# File 'lib/crono_trigger/execution_tracker.rb', line 3

def initialize(schedulable)
  @schedulable = schedulable
end

Class Method Details

.track(schedulable, &pr) ⇒ Object



7
8
9
# File 'lib/crono_trigger/execution_tracker.rb', line 7

def self.track(schedulable, &pr)
  new(schedulable).track(&pr)
end

Instance Method Details

#track(&pr) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crono_trigger/execution_tracker.rb', line 11

def track(&pr)
  if @schedulable.track_execution
    begin
      execution = @schedulable.crono_trigger_executions.create_with_timestamp!
      result = pr.call
      case result
      when :ok
        execution.complete!
      when :retry
        execution.retrying!
      when :abort
        execution.aborted!
      else
        execution.complete!
      end
    rescue => e
      execution.error!(e)
      raise
    end
  else
    pr.call
  end
end