Class: Chicago::ETL::TaskInvocation

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/chicago/etl/task_invocation.rb

Instance Method Summary collapse

Instance Method Details

#finished?Boolean

Returns true if this task has finished running successfully.

Returns:

  • (Boolean)


25
26
27
# File 'lib/chicago/etl/task_invocation.rb', line 25

def finished?
  state == "Finished"
end

#performObject

Executes a block of code.

Sets the state to “Error” and re-raises any exception that the block of code raises.

Raises:

  • (RuntimeError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chicago/etl/task_invocation.rb', line 11

def perform
  raise RuntimeError.new("The task #{name} in batch #{batch_id} has already run") if finished?
  update(:state => "Started", :attempts => attempts + 1)
  begin
    yield
  rescue Exception => e
    update(:state => "Error")
    batch.error if batch
    raise e
  end
  update(:state => "Finished", :finished_at => Time.now)
end