module RuneRb::System::Utils::Pipeline
A pipeline object organizes the sequential execution of a set of tasks. Tasks are registered to it's stack and are arranged automatically or manually prior to processing it's stack.
Constants
- OPERATIONS
@!attribute [r]
OPERATIONS
@return [Hash] a container for pipeline operations.
Public Instance Methods
post(key, options, &work)
click to toggle source
Pushes work to an internal {SortedStack} relative to the provided key. @param options [Hash] Parameters for the Task. @param work [Proc] Work to be executed by the Task.
# File deployment/app/system/utils/pipeline.rb, line 11 def post(key, options, &work) task = RuneRb::System::Types::Task.new(options, &work) OPERATIONS[key] ||= { stack: RuneRb::System::Types::SortedStack.new, operation: Fiber.new do loop do attempts = 0 return if OPERATIONS[key][:stack].empty? begin OPERATIONS[key][:stack].sort! OPERATIONS[key][:stack].first.start Fiber.yield(true) rescue StandardError => e err 'An error was raised by a Task in the stack!', e, e.message, e.backtrace&.join("\n") attempts += 1 if attempts >= ENV['RRB_STACK_RETRIES'].to_i OPERATIONS[key][:stack].clear break else retry end end end end } OPERATIONS[key][:stack] << task end