Class: Syctask::TaskTracker
- Inherits:
-
Object
- Object
- Syctask::TaskTracker
- Defined in:
- lib/syctask/task_tracker.rb
Overview
TaskTracker provides methods to start a task and stop a task. The objective is to track the processing time for a task. The processing time can be analyzed with the TaskStatistics class. When a task is started it is saved to the started_tasks file. If another task is started the currently active task is stopped and the newly started file is put on top of the started_tasks file. When stopping a task the currently started tasks will be returned and one of the idling tasks can be restarted. When a task is stopped the processing time is added to the task’s lead_time field.
Constant Summary collapse
- TRACKED_TASKS_FILE =
File name of the file where the tracked files are saved to
Syctask::TRACKED_TASK
- TASK_LOG_FILE =
File name of the task log file
Syctask::TASKS_LOG
Instance Method Summary collapse
-
#initialize ⇒ TaskTracker
constructor
Creates a new TaskTracker.
-
#start(task, show = true) ⇒ Object
When a task is started it is saved with the start time.
-
#stop ⇒ Object
When a task is stopped it is removed from the started_tasks file and the processing time is added to the lead_time field of the task.
-
#tracked_task ⇒ Object
Retrieves the currently tracked task returns nil if no task is tracked.
Constructor Details
#initialize ⇒ TaskTracker
Creates a new TaskTracker
25 26 27 28 |
# File 'lib/syctask/task_tracker.rb', line 25 def initialize @service = Syctask::TaskService.new load_tracks end |
Instance Method Details
#start(task, show = true) ⇒ Object
When a task is started it is saved with the start time. If a task is already tracked it is stopped (see #stop). A started task will print every second a message to the console if the show parameter is true. start returns
- false, nil
-
if the task is already tracked
- true, nil
-
if the task is started and no task was running.
- true, task
-
if task is started and the previously running task stopped
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/syctask/task_tracker.rb', line 37 def start(task, show=true) raise ArgumentError, "Error: Task without directory.\n"+ "--> Update task with syctask -t <dir> update "+ "#{task.id}" unless task.dir index = @tasks.find_index(task) return [false, nil] if not index.nil? and index == 0 stopped_task = stop track = Track.new(task) track.start(show) log_task(:start, track) @tracks.insert(0,track) @tasks.insert(0,task) save_tracks [true, stopped_task] end |
#stop ⇒ Object
When a task is stopped it is removed from the started_tasks file and the processing time is added to the lead_time field of the task. #stop returns the stopped task in an Array or an empty Array if no task is running an hence no task can be stopped.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/syctask/task_tracker.rb', line 64 def stop return nil unless @tasks[0] task = @tasks[0] task.update_lead_time(@tracks[0].stop) @service.save(task.dir, task) log_task(:stop, @tracks[0]) @tracks.delete_at(0) @tasks.delete_at(0) save_tracks task end |
#tracked_task ⇒ Object
Retrieves the currently tracked task returns nil if no task is tracked
81 82 83 |
# File 'lib/syctask/task_tracker.rb', line 81 def tracked_task @tasks[0] end |