Class: Lemans::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/lemans/runner.rb,
lib/lemans/runner/task.rb,
lib/lemans/runner/executor.rb

Overview

Runner orchestrates tasks execution

Defined Under Namespace

Classes: Executor, Shutdown, Summary, Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, tasks, store: nil, reporter: nil, executor: nil, resume: false) ⇒ Runner

Returns a new instance of Runner.



25
26
27
28
29
30
31
32
# File 'lib/lemans/runner.rb', line 25

def initialize(config, tasks, store: nil, reporter: nil, executor: nil, resume: false)
  @config = config
  @tasks = tasks
  @store = store
  @reporter = reporter
  @executor = executor || Executor.new(config.concurrency)
  @resuming = resume
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



21
22
23
# File 'lib/lemans/runner.rb', line 21

def config
  @config
end

#reporterObject (readonly)

Returns the value of attribute reporter.



21
22
23
# File 'lib/lemans/runner.rb', line 21

def reporter
  @reporter
end

#storeObject (readonly)

Returns the value of attribute store.



21
22
23
# File 'lib/lemans/runner.rb', line 21

def store
  @store
end

#tasksObject (readonly)

Returns the value of attribute tasks.



21
22
23
# File 'lib/lemans/runner.rb', line 21

def tasks
  @tasks
end

Instance Method Details

#attemptsObject



36
37
38
39
40
41
42
43
# File 'lib/lemans/runner.rb', line 36

def attempts
  @attempts ||= config.agent.models.flat_map do |model|
    @tasks.flat_map do |task|
      completed = resuming? ? completed_attempts(task, model) : 0
      ((completed + 1)..config.attempts).map { Task.new(model, task, store:, index: it) }
    end
  end
end

#resuming?Boolean

Returns:

  • (Boolean)


34
# File 'lib/lemans/runner.rb', line 34

def resuming? = @resuming

#run(reporter = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/lemans/runner.rb', line 45

def run(reporter = nil)
  @reporter = reporter if reporter

  store&.setup

  results_handle = executor.start
  interrupted = false
  begin
    attempts.shuffle.each { executor << it.with_reporter(reporter) }
    executor.shutdown
  rescue Interrupt
    interrupted = true
    reporter ? reporter.record(:interrupted) : warn("Interrupted. Exiting...")
    executor.terminate
  end

  results = results_handle.results
  Summary.new(results:, interrupted:)
end