Class: Pipeline::Stage::Base
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pipeline::Stage::Base
- Defined in:
- lib/pipeline/stage/base.rb
Constant Summary collapse
- @@chain =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #completed? ⇒ Boolean
- #perform ⇒ Object
-
#run ⇒ Object
Subclass must implement this as part of the contract.
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_chain ⇒ Object
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_initialize ⇒ Object
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
37 38 39 |
# File 'lib/pipeline/stage/base.rb', line 37 def completed? status == :completed end |
#perform ⇒ Object
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.}") logger.info(e.backtrace.join("\n")) self. = e. self.status = :failed raise e end end |
#run ⇒ Object
Subclass must implement this as part of the contract
58 |
# File 'lib/pipeline/stage/base.rb', line 58 def run; end |