Class: Signalman::BaseHandler
- Inherits:
-
Object
- Object
- Signalman::BaseHandler
show all
- Defined in:
- lib/signalman.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(event, current_time) ⇒ BaseHandler
Returns a new instance of BaseHandler.
13
14
15
|
# File 'lib/signalman.rb', line 13
def initialize(event, current_time)
@event, @current_time = event, current_time
end
|
Instance Attribute Details
#current_time ⇒ Object
Returns the value of attribute current_time.
6
7
8
|
# File 'lib/signalman.rb', line 6
def current_time
@current_time
end
|
#event ⇒ Object
Returns the value of attribute event.
6
7
8
|
# File 'lib/signalman.rb', line 6
def event
@event
end
|
Class Method Details
.call(event) ⇒ Object
8
9
10
11
|
# File 'lib/signalman.rb', line 8
def self.call(event)
current_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
new(event, current_time).start
end
|
Instance Method Details
#create_event(payload = nil) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/signalman.rb', line 29
def create_event(payload = nil)
payload ||= event.payload
Event.create(
name: event.name,
started_at: started_at,
finished_at: finished_at,
duration: event.duration,
payload: payload
)
rescue ActiveRecord::StatementInvalid => e
Rails.logger.error "[Signalman] #{e.message}"
end
|
#finished_at ⇒ Object
49
50
51
|
# File 'lib/signalman.rb', line 49
def finished_at
Time.current - ((current_time - event.end) / 1_000)
end
|
#process ⇒ Object
21
22
23
|
# File 'lib/signalman.rb', line 21
def process
create_event
end
|
#skip? ⇒ Boolean
25
26
27
|
# File 'lib/signalman.rb', line 25
def skip?
false
end
|
#start ⇒ Object
17
18
19
|
# File 'lib/signalman.rb', line 17
def start
process unless skip?
end
|
#started_at ⇒ Object
Time measure since system boot with Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
45
46
47
|
# File 'lib/signalman.rb', line 45
def started_at
Time.current - ((current_time - event.time) / 1_000)
end
|