Class: Syctask::Track
- Inherits:
-
Object
- Object
- Syctask::Track
- Defined in:
- lib/syctask/task_tracker.rb
Overview
A Track holds a task and stops the time the task is processed. The Track will print every second the elapsed time and the time left to the specified Task#duration.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Directory where the tracked task is saved.
-
#id ⇒ Object
readonly
ID of the tracked task.
-
#started ⇒ Object
readonly
When tracking started.
-
#stopped ⇒ Object
readonly
When tracking stopped.
-
#title ⇒ Object
readonly
Title of the tracked task.
Instance Method Summary collapse
-
#initialize(task) ⇒ Track
constructor
Creates a new Track for the provided task.
-
#start(show) ⇒ Object
Starts the tracking and a timer that will print to STDOUT every second the elapsed time and the time left until Task#duration.
-
#stop ⇒ Object
Stops the task tracking and returns the lead time of the task.
Constructor Details
Instance Attribute Details
#dir ⇒ Object (readonly)
Directory where the tracked task is saved
138 139 140 |
# File 'lib/syctask/task_tracker.rb', line 138 def dir @dir end |
#id ⇒ Object (readonly)
ID of the tracked task
140 141 142 |
# File 'lib/syctask/task_tracker.rb', line 140 def id @id end |
#started ⇒ Object (readonly)
When tracking started
144 145 146 |
# File 'lib/syctask/task_tracker.rb', line 144 def started @started end |
#stopped ⇒ Object (readonly)
When tracking stopped
146 147 148 |
# File 'lib/syctask/task_tracker.rb', line 146 def stopped @stopped end |
#title ⇒ Object (readonly)
Title of the tracked task
142 143 144 |
# File 'lib/syctask/task_tracker.rb', line 142 def title @title end |
Instance Method Details
#start(show) ⇒ Object
Starts the tracking and a timer that will print to STDOUT every second the elapsed time and the time left until Task#duration
159 160 161 162 163 164 |
# File 'lib/syctask/task_tracker.rb', line 159 def start(show) @started ||= Time.now # start a timer that prints id and elapsed time FileUtils.touch @semaphore system "console_timer #{@duration} #{@id} #{@semaphore} &" if show end |
#stop ⇒ Object
Stops the task tracking and returns the lead time of the task
167 168 169 170 171 |
# File 'lib/syctask/task_tracker.rb', line 167 def stop FileUtils.rm @semaphore if @semaphore and File.exist? @semaphore @stopped ||= Time.now @stopped - @started end |