class Dynflow::Testing::InThreadExecutor

Public Class Methods

new(world) click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 4
def initialize(world)
  @world = world
  @director = Director.new(@world)
  @work_items = Queue.new
end

Public Instance Methods

clock_tick() click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 36
def clock_tick
  @world.clock.progress
end
event(execution_plan_id, step_id, event, future = Concurrent.future) click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 28
def event(execution_plan_id, step_id, event, future = Concurrent.future)
  event = (Director::Event[execution_plan_id, step_id, event, future])
  @director.handle_event(event).each do |work_item|
    @work_items << work_item
  end
  future
end
execute(execution_plan_id, finished = Concurrent.future, _wait_for_acceptance = true) click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 10
def execute(execution_plan_id, finished = Concurrent.future, _wait_for_acceptance = true)
  feed_queue(@director.start_execution(execution_plan_id, finished))
  process_work_items
  finished
end
feed_queue(work_items) click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 40
def feed_queue(work_items)
  work_items.each { |work_item| @work_items.push(work_item) }
end
handle_work(work_item) click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 23
def handle_work(work_item)
  work_item.execute
  @director.work_finished(work_item)
end
process_work_items() click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 16
def process_work_items
  until @work_items.empty?
    feed_queue(handle_work(@work_items.pop))
    clock_tick
  end
end
terminate(future = Concurrent.future) click to toggle source
# File lib/dynflow/testing/in_thread_executor.rb, line 44
def terminate(future = Concurrent.future)
  @director.terminate
  future.success true
rescue => e
  future.fail e
end