Module: Pipeline::ApiMethods
- Included in:
- Pipeline
- Defined in:
- lib/pipeline/api_methods.rb
Overview
This is the external API for Pipeline. Its methods should be called by client code wanting to manipulate/execute pipelines.
Instance Method Summary collapse
-
#cancel(id) ⇒ Object
Cancels execution of a paused pipeline.
-
#resume(id) ⇒ Object
Enqueues execution of a paused pipeline for retrying.
-
#start(pipeline) ⇒ Object
Used to enqueue a pipeline execution.
Instance Method Details
#cancel(id) ⇒ Object
Cancels execution of a paused pipeline. Raises InvalidPipelineError if a pipeline can not be found with the provided id. Raises InvalidStatusError if pipeline is in an invalid state for cancelling (e.g. already cancelled, or completed)
32 33 34 35 36 37 |
# File 'lib/pipeline/api_methods.rb', line 32 def cancel(id) pipeline = Base.find(id) pipeline.cancel rescue ActiveRecord::RecordNotFound raise InvalidPipelineError.new("Invalid pipeline") end |
#resume(id) ⇒ Object
Enqueues execution of a paused pipeline for retrying. Raises InvalidPipelineError if a pipeline can not be found with the provided id. Raises InvalidStatusError if pipeline is in an invalid state for resuming (e.g. already cancelled, or completed)
20 21 22 23 24 25 26 |
# File 'lib/pipeline/api_methods.rb', line 20 def resume(id) pipeline = Base.find(id) pipeline.resume Delayed::Job.enqueue(pipeline) rescue ActiveRecord::RecordNotFound raise InvalidPipelineError.new("Invalid pipeline") end |
#start(pipeline) ⇒ Object
Used to enqueue a pipeline execution. Raises InvalidPipelineError if the passed in argument is not a subclass of Pipeline::Base. The pipeline will be saved (if not already) and its id will be returned.
9 10 11 12 13 14 |
# File 'lib/pipeline/api_methods.rb', line 9 def start(pipeline) raise InvalidPipelineError.new("Invalid pipeline") unless pipeline.is_a?(Pipeline::Base) pipeline.save! if pipeline.new_record? Delayed::Job.enqueue(pipeline) pipeline.id end |