Class: MaintenanceTasks::TaskDataIndex Private
- Inherits:
-
Object
- Object
- MaintenanceTasks::TaskDataIndex
- Defined in:
- app/models/maintenance_tasks/task_data_index.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class that represents the data related to a Task. Such information can be sourced from a Task or from existing Run records for a Task that was since deleted. This class contains higher-level information about the Task, such as its status and category.
Instances of this class replace a Task class instance in cases where we don’t need the actual Task subclass.
Instance Attribute Summary collapse
-
#name ⇒ String
(also: #to_s)
readonly
private
The name of the Task.
- #related_run ⇒ Object readonly private
Class Method Summary collapse
-
.available_tasks ⇒ Array<TaskDataIndex>
private
Returns a list of sorted Task Data objects that represent the available Tasks.
Instance Method Summary collapse
-
#category ⇒ Symbol
private
Retrieves the Task’s category, which is one of active, new, or completed.
-
#initialize(name, related_run = nil) ⇒ TaskDataIndex
constructor
private
Initializes a Task Data with a name and optionally a related run.
-
#status ⇒ String
private
Returns the status of the latest active or completed Run, if present.
Constructor Details
#initialize(name, related_run = nil) ⇒ TaskDataIndex
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a Task Data with a name and optionally a related run.
55 56 57 58 |
# File 'app/models/maintenance_tasks/task_data_index.rb', line 55 def initialize(name, = nil) @name = name @related_run = end |
Instance Attribute Details
#name ⇒ String (readonly) Also known as: to_s
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the name of the Task.
61 62 63 |
# File 'app/models/maintenance_tasks/task_data_index.rb', line 61 def name @name end |
#related_run ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'app/models/maintenance_tasks/task_data_index.rb', line 62 def @related_run end |
Class Method Details
.available_tasks ⇒ Array<TaskDataIndex>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a list of sorted Task Data objects that represent the available Tasks.
Tasks are sorted by category, and within a category, by Task name. Determining a Task’s category requires their latest Run records. Two queries are done to get the currently active and completed Run records, and Task Data instances are initialized with these related run values.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/maintenance_tasks/task_data_index.rb', line 25 def available_tasks tasks = [] task_names = Task.load_all.map(&:name) active_runs = Run.with_attached_csv.active.where(task_name: task_names) active_runs.each do |run| tasks << TaskDataIndex.new(run.task_name, run) task_names.delete(run.task_name) end completed_runs = Run.completed.where(task_name: task_names) last_runs = Run.with_attached_csv.where(id: completed_runs.select("MAX(id) as id").group(:task_name)) task_names.map do |task_name| last_run = last_runs.find { |run| run.task_name == task_name } tasks << TaskDataIndex.new(task_name, last_run) end # We add an additional sorting key (status) to avoid possible # inconsistencies across database adapters when a Task has # multiple active Runs. tasks.sort_by! { |task| [task.name, task.status] } end |
Instance Method Details
#category ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieves the Task’s category, which is one of active, new, or completed.
77 78 79 80 81 82 83 84 85 |
# File 'app/models/maintenance_tasks/task_data_index.rb', line 77 def category if .present? && .active? :active elsif .nil? :new else :completed end end |
#status ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the status of the latest active or completed Run, if present. If the Task does not have any Runs, the Task status is ‘new`.
70 71 72 |
# File 'app/models/maintenance_tasks/task_data_index.rb', line 70 def status &.status || "new" end |