Sha256: ab239c4a59dae7adec1baffd72cdcb7a83f7698c1f9a49c68fb9c5ab9456ff46
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
# frozen_string_literal: true # # Copyright (c) 2020-present, Blue Marble Payroll, LLC # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # require_relative 'jobs' require_relative 'output' require_relative 'payload' require_relative 'step' module Burner # The root package. A Pipeline contains the job configurations along with the steps. The steps # referens jobs and tell you the order of the jobs to run. class Pipeline acts_as_hashable class JobNotFoundError < StandardError; end attr_reader :steps def initialize(jobs: [], steps: []) jobs_by_name = Jobs.array(jobs).map { |job| [job.name, job] }.to_h @steps = Array(steps).map do |step_name| job = jobs_by_name[step_name.to_s] raise JobNotFoundError, "#{step_name} was not declared as a job" unless job Step.new(job) end end # The main entry-point for kicking off a pipeline. def execute(output: Output.new, payload: Payload.new) output.write("Pipeline started with #{steps.length} step(s)") output_params(payload.params, output) output.ruler time_in_seconds = Benchmark.measure do steps.each do |step| return_value = step.perform(output, payload) if return_value.is_a?(FalseClass) output.detail('Job returned false, ending pipeline.') break end end end.real.round(3) output.ruler output.write("Pipeline ended, took #{time_in_seconds} second(s) to complete") payload end private def output_params(params, output) if params.keys.any? output.write('Parameters:') else output.write('No parameters passed in.') end params.each { |key, value| output.detail("#{key}: #{value}") } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
burner-1.0.0.pre.alpha.5 | lib/burner/pipeline.rb |
burner-1.0.0.pre.alpha.4 | lib/burner/pipeline.rb |