Class: Lemans::Runner::Task
- Inherits:
-
Object
- Object
- Lemans::Runner::Task
- Extended by:
- Forwardable
- Defined in:
- lib/lemans/runner/task.rb
Overview
A single task to run: a thin wrapper owning status, reporting, and result persistence; the actual work is the Trial's.
Constant Summary collapse
- RUN_STATUSES =
%i[pending running finished].freeze
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(model, task_definition, index: 0, store: nil, reporter: nil) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
- #with_reporter(reporter) ⇒ Object
Constructor Details
#initialize(model, task_definition, index: 0, store: nil, reporter: nil) ⇒ Task
Returns a new instance of Task.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lemans/runner/task.rb', line 25 def initialize(model, task_definition, index: 0, store: nil, reporter: nil) @model = model @definition = task_definition @index = index @store = store @reporter = reporter @status = :pending # prepare the result object: it's used by the actual execution down the stack @result = Result.from_task(definition, index:, model: model || config.models.first) end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
12 13 14 |
# File 'lib/lemans/runner/task.rb', line 12 def index @index end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
12 13 14 |
# File 'lib/lemans/runner/task.rb', line 12 def model @model end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
12 13 14 |
# File 'lib/lemans/runner/task.rb', line 12 def result @result end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/lemans/runner/task.rb', line 12 def status @status end |
Instance Method Details
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lemans/runner/task.rb', line 42 def run @status = :running reporter&.record(:started, self) execute! @status = :finished reporter&.record(:finished, result) result ensure store&.save(result) unless result.pending? end |
#with_reporter(reporter) ⇒ Object
37 38 39 40 |
# File 'lib/lemans/runner/task.rb', line 37 def with_reporter(reporter) @reporter = reporter self end |