Class: Skywalking::Reporter::Scheduler::Timer
- Inherits:
-
Object
- Object
- Skywalking::Reporter::Scheduler::Timer
- Defined in:
- lib/skywalking/reporter/scheduler.rb
Instance Attribute Summary collapse
-
#job_interval ⇒ Object
readonly
Returns the value of attribute job_interval.
-
#job_name ⇒ Object
readonly
Returns the value of attribute job_name.
-
#latest_trigger_time ⇒ Object
readonly
Returns the value of attribute latest_trigger_time.
-
#next_trigger_time ⇒ Object
readonly
Returns the value of attribute next_trigger_time.
Instance Method Summary collapse
- #adjust_next_trigger_time(time) ⇒ Object
- #gen_next_trigger_time ⇒ Object
- #init_next_trigger_time ⇒ Object
-
#initialize(job_name, job_interval) ⇒ Timer
constructor
A new instance of Timer.
- #latest_trigger ⇒ Object
- #need_trigger?(now = Process.clock_gettime(Process::CLOCK_REALTIME)) ⇒ Boolean
- #set_latest_trigger_time ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(job_name, job_interval) ⇒ Timer
Returns a new instance of Timer.
112 113 114 115 116 117 118 119 |
# File 'lib/skywalking/reporter/scheduler.rb', line 112 def initialize(job_name, job_interval) @job_name = job_name @job_interval = job_interval @start_time = Process.clock_gettime(Process::CLOCK_REALTIME) @latest_trigger_time = nil init_next_trigger_time end |
Instance Attribute Details
#job_interval ⇒ Object (readonly)
Returns the value of attribute job_interval.
110 111 112 |
# File 'lib/skywalking/reporter/scheduler.rb', line 110 def job_interval @job_interval end |
#job_name ⇒ Object (readonly)
Returns the value of attribute job_name.
110 111 112 |
# File 'lib/skywalking/reporter/scheduler.rb', line 110 def job_name @job_name end |
#latest_trigger_time ⇒ Object (readonly)
Returns the value of attribute latest_trigger_time.
110 111 112 |
# File 'lib/skywalking/reporter/scheduler.rb', line 110 def latest_trigger_time @latest_trigger_time end |
#next_trigger_time ⇒ Object (readonly)
Returns the value of attribute next_trigger_time.
110 111 112 |
# File 'lib/skywalking/reporter/scheduler.rb', line 110 def next_trigger_time @next_trigger_time end |
Instance Method Details
#adjust_next_trigger_time(time) ⇒ Object
138 139 140 |
# File 'lib/skywalking/reporter/scheduler.rb', line 138 def adjust_next_trigger_time(time) @next_trigger_time -= time end |
#gen_next_trigger_time ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/skywalking/reporter/scheduler.rb', line 146 def gen_next_trigger_time now = Process.clock_gettime(Process::CLOCK_REALTIME) return now if @job_interval == 0 ret = @latest_trigger_time || now ret += @job_interval while ret <= now ret end |
#init_next_trigger_time ⇒ Object
121 122 123 |
# File 'lib/skywalking/reporter/scheduler.rb', line 121 def init_next_trigger_time @next_trigger_time = gen_next_trigger_time end |
#latest_trigger ⇒ Object
134 135 136 |
# File 'lib/skywalking/reporter/scheduler.rb', line 134 def latest_trigger @start_time || @latest_trigger_time end |
#need_trigger?(now = Process.clock_gettime(Process::CLOCK_REALTIME)) ⇒ Boolean
142 143 144 |
# File 'lib/skywalking/reporter/scheduler.rb', line 142 def need_trigger?(now = Process.clock_gettime(Process::CLOCK_REALTIME)) now >= @next_trigger_time end |
#set_latest_trigger_time ⇒ Object
125 126 127 |
# File 'lib/skywalking/reporter/scheduler.rb', line 125 def set_latest_trigger_time @latest_trigger_time = Process.clock_gettime(Process::CLOCK_REALTIME) end |
#to_s ⇒ Object
129 130 131 132 |
# File 'lib/skywalking/reporter/scheduler.rb', line 129 def to_s "<Timer job_name: #{@job_name}, job_interval: #{@job_interval}, start_time: #{@start_time}, latest_trigger_time: #{@latest_trigger_time}>" end |