Class: ConcurrentPipeline::Pipeline::Wrapper
- Inherits:
-
Object
- Object
- ConcurrentPipeline::Pipeline::Wrapper
- Defined in:
- lib/concurrent_pipeline/pipeline.rb
Instance Attribute Summary collapse
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Instance Method Summary collapse
- #changeset ⇒ Object
- #create_pipeline_steps ⇒ Object
- #done? ⇒ Boolean
- #id ⇒ Object
-
#initialize(pipeline:, pool:) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #perform ⇒ Object
- #pipeline_steps ⇒ Object
- #ready? ⇒ Boolean
- #should_perform? ⇒ Boolean
- #store ⇒ Object
- #stream(type, payload) ⇒ Object
Constructor Details
#initialize(pipeline:, pool:) ⇒ Wrapper
Returns a new instance of Wrapper.
33 34 35 36 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 33 def initialize(pipeline:, pool:) @pipeline = pipeline @pool = pool end |
Instance Attribute Details
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
32 33 34 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 32 def pipeline @pipeline end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
32 33 34 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 32 def pool @pool end |
Instance Method Details
#changeset ⇒ Object
135 136 137 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 135 def changeset pipeline.changeset end |
#create_pipeline_steps ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 85 def create_pipeline_steps sequence = ( if pipeline.respond_to?(:steps) pipeline.steps else [:perform] end ) sequence.each_with_index do |sub_seq, i| Array(sub_seq).each do |step_name| changeset.create( PipelineStep, pipeline_id: id, name: step_name, sequence: i ) end end end |
#done? ⇒ Boolean
123 124 125 126 127 128 129 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 123 def done? if pipeline.respond_to?(:done?) pipeline.done? else !pipeline_steps.empty? && pipeline_steps.all?(&:completed_at) end end |
#id ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 38 def id pipeline_id = ( if pipeline.class.target_type pipeline.target.id end ) [pipeline.class.name, pipeline_id].compact.join("__") end |
#perform ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 48 def perform if pipeline_steps.empty? create_pipeline_steps else pipeline_steps .reject(&:completed_at) .group_by(&:sequence) .values .first .map { |step| wrapper = self -> () do begin wrapper.pipeline.public_send(step.name) wrapper.changeset.update( step, completed_at: Time.now.iso8601, result: :success ) rescue => e wrapper.changeset.update( step, completed_at: Time.now.iso8601, result: :failure, error: {class: e.class, message: e., backtrace: e.backtrace} ) end end } .then { pool.process(_1) } end end |
#pipeline_steps ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 106 def pipeline_steps @pipeline_steps ||= ( store .all(PipelineStep) .select { _1.pipeline_id == id } .sort_by(&:sequence) ) end |
#ready? ⇒ Boolean
115 116 117 118 119 120 121 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 115 def ready? if pipeline.respond_to?(:ready?) pipeline.ready? else true end end |
#should_perform? ⇒ Boolean
81 82 83 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 81 def should_perform? ready? && !done? end |
#store ⇒ Object
131 132 133 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 131 def store pipeline.store end |
#stream(type, payload) ⇒ Object
139 140 141 |
# File 'lib/concurrent_pipeline/pipeline.rb', line 139 def stream(type, payload) pipeline.stream.push(type, payload) end |