Class: Skywalking::Reporter::Scheduler::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/skywalking/reporter/scheduler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_intervalObject (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_nameObject (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_timeObject (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_timeObject (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_timeObject



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_timeObject



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_triggerObject



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

Returns:

  • (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_timeObject



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_sObject



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