Class: Pipeline::Stage::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/pipeline/stage/base.rb

Constant Summary collapse

@@chain =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.>>(next_stage) ⇒ Object



17
18
19
20
# File 'lib/pipeline/stage/base.rb', line 17

def self.>>(next_stage)
  @@chain << self
  next_stage
end

.build_chainObject



22
23
24
25
26
# File 'lib/pipeline/stage/base.rb', line 22

def self.build_chain
  chain = @@chain + [self]
  @@chain = []
  chain
end

Instance Method Details

#after_initializeObject



30
31
32
33
34
35
# File 'lib/pipeline/stage/base.rb', line 30

def after_initialize
  if new_record?
    self[:status] = :not_started
    self.name ||= (default_name || self.class).to_s
  end
end

#completed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pipeline/stage/base.rb', line 37

def completed?
  status == :completed
end

#performObject

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pipeline/stage/base.rb', line 41

def perform
  reload unless new_record?
  raise InvalidStatusError.new(status) unless [:not_started, :failed].include?(status)
  begin
    _setup
    run
    self.status = :completed
  rescue Exception => e
    logger.info("Error on stage #{default_name}: #{e.message}")
    logger.info(e.backtrace.join("\n"))
    self.message = e.message
    self.status = :failed
    raise e
  end
end

#runObject

Subclass must implement this as part of the contract



58
# File 'lib/pipeline/stage/base.rb', line 58

def run; end