Class: MGit::DurationRecorder
- Inherits:
-
Object
- Object
- MGit::DurationRecorder
show all
- Includes:
- Status
- Defined in:
- lib/m-git/foundation/duration_recorder.rb
Overview
Defined Under Namespace
Modules: Status
Constant Summary
collapse
- DEFAULT_DURATION_KEY =
'default_duration_key'
- @@status =
{}
- @@duration =
{}
- @@time_stamp =
{}
- @@lock =
Mutex.new
Constants included
from Status
Status::IDLE, Status::PAUSE, Status::RUNNING
Class Method Summary
collapse
Class Method Details
.end(duration_key: DEFAULT_DURATION_KEY, use_lock: false) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/m-git/foundation/duration_recorder.rb', line 60
def self.end(duration_key:DEFAULT_DURATION_KEY, use_lock:false)
mutex_exec(use_lock) {
if @@status[duration_key] != IDLE
current = Time.new.to_f
@@duration[duration_key] += (current - @@time_stamp[duration_key])
@@time_stamp.delete(duration_key)
@@status[duration_key] = IDLE
return @@duration[duration_key]
else
puts '没有需要停止的计时'
end
}
end
|
.pause(duration_key: DEFAULT_DURATION_KEY, use_lock: false) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/m-git/foundation/duration_recorder.rb', line 40
def self.pause(duration_key:DEFAULT_DURATION_KEY, use_lock:false)
mutex_exec(use_lock) {
if @@status[duration_key] == RUNNING
current = Time.new.to_f
@@duration[duration_key] += (current - @@time_stamp[duration_key])
@@time_stamp.delete(duration_key)
@@status[duration_key] = PAUSE
end
}
end
|
.resume(duration_key: DEFAULT_DURATION_KEY, use_lock: false) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/m-git/foundation/duration_recorder.rb', line 51
def self.resume(duration_key:DEFAULT_DURATION_KEY, use_lock:false)
mutex_exec(use_lock) {
if @@status[duration_key] == PAUSE
@@time_stamp[duration_key] = Time.new.to_f
@@status[duration_key] = RUNNING
end
}
end
|
.start(duration_key: DEFAULT_DURATION_KEY, use_lock: false) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/m-git/foundation/duration_recorder.rb', line 27
def self.start(duration_key:DEFAULT_DURATION_KEY, use_lock:false)
mutex_exec(use_lock) {
status = IDLE if @@status[duration_key].nil?
if status == IDLE
@@duration[duration_key] = 0.0
@@time_stamp[duration_key] = Time.new.to_f
@@status[duration_key] = RUNNING
else
puts '需要停止计时后重新开始计时'
end
}
end
|