alacrity-rails 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b063f660214c374b47a2cfbad8e91c85b6cca2d
4
- data.tar.gz: 56b178a5f5e29f4d88f421465a927ece164a2e39
3
+ metadata.gz: 15e0a853985dc0e53009d9456ee640112a1cba67
4
+ data.tar.gz: a82aa5c5d092b4dc9b38cff22c8d7d91fbb813a9
5
5
  SHA512:
6
- metadata.gz: a9fa5e1f9351d8f9e95f1dccb7563d7bfba39538e2f610f3454eb411e23b80b707c7fa58613fe09764437c9cf14a8399d8acc874fd86d7a22b36bef9b0ae950a
7
- data.tar.gz: 8a47e73f3c8eb1ba0a529ea421f83fc127dcc3892e5a65e4bc4ffa58e76d6ad353c1a5410b07d46fb0abae5b1dd39a13d0d19bd10f97ace60e7dc8565c0ee613
6
+ metadata.gz: c200798ec7d65f132b51814e92ab48fef065ecc032f63610b8843ce0a54f6af643c3c019a18635c7d71c3fb89f83df37ad5874b8d2aa0522b1f198d15c422072
7
+ data.tar.gz: 6885ef7ef6ab63c2093416be9977c3f9f9cae58edab0d1e8e624c4742a5ba8a11ab32d35de280763c96c7bcefa54c8339b2c4d89be62a2b224c343da84ae9639
@@ -1,10 +1,9 @@
1
1
  module AlacrityRails::Transaction
2
2
  class WebTransaction < Base
3
- attr_accessor :url, :middleware_started_at, :middleware_finished_at,
4
- :controller, :action, :format, :method, :status
3
+ attr_accessor :url, :controller, :action, :format, :method, :status
5
4
 
6
5
  def initialize(env={})
7
- self.middleware_started_at = absolute_time(DateTime.now)
6
+ @middleware_started_at = DateTime.now
8
7
  self.url = env['REQUEST_URI']
9
8
  self.method = env['REQUEST_METHOD']
10
9
  end
@@ -16,41 +15,35 @@ module AlacrityRails::Transaction
16
15
  end
17
16
 
18
17
  def store_timeline_event(data)
19
- started_at = absolute_time(data[:started_at].to_datetime)
20
- finished_at = absolute_time(data[:finished_at].to_datetime)
21
-
22
18
  timeline_events << {
23
19
  name: data[:name],
24
20
  event_type: data[:event_type],
25
21
  engine: data[:engine],
26
- started_at: started_at,
27
- finished_at: finished_at,
22
+ started_at: data[:started_at],
23
+ finished_at: data[:finished_at],
28
24
  detail: data[:detail]
29
- } unless timeline_events.detect do |event|
30
- event[:engine] == data[:engine] &&
31
- event[:started_at] == started_at &&
32
- event[:finished_at] == finished_at &&
33
- event[:detail] == data[:detail]
34
- end
25
+ }
35
26
  end
36
27
 
37
28
  def finalize!
38
- self.middleware_finished_at = absolute_time(DateTime.now)
29
+ @middleware_finished_at = DateTime.now
39
30
  end
40
31
 
41
32
  def as_json(*args)
33
+ middleware_started_at = absolute_time(@middleware_started_at)
34
+ middleware_finished_at = absolute_time(@middleware_finished_at) || absolute_time(DateTime.now)
42
35
  {
43
36
  environment: AlacrityRails::ServerConfig.environment,
44
37
  url: url,
45
38
  controller: controller,
46
39
  action: action,
47
- middleware_elapsed: (middleware_finished_at || absolute_time(DateTime.now)) - middleware_started_at,
40
+ middleware_elapsed: middleware_finished_at - middleware_started_at,
48
41
  middleware_started_at: middleware_started_at,
49
42
  middleware_finished_at: middleware_finished_at,
50
43
  format: format,
51
44
  method: method,
52
45
  status: status,
53
- timeline_events: timeline_events,
46
+ timeline_events: prepared_timeline_events,
54
47
  timestamp: Time.now.utc
55
48
  }
56
49
  end
@@ -63,6 +56,16 @@ module AlacrityRails::Transaction
63
56
  @timeline_events ||= []
64
57
  end
65
58
 
59
+ def prepared_timeline_events
60
+ timeline_events.uniq do |timeline_event|
61
+ timeline_event.values_at(:engine, :started_at, :finished_at, :detail).join('~')
62
+ end.map do |timeline_event|
63
+ timeline_event[:started_at] = absolute_time(timeline_event[:started_at].to_datetime)
64
+ timeline_event[:finished_at] = absolute_time(timeline_event[:finished_at].to_datetime)
65
+ timeline_event
66
+ end
67
+ end
68
+
66
69
  def absolute_time(datetime)
67
70
  datetime.strftime('%Q').to_i
68
71
  end
@@ -1,3 +1,3 @@
1
1
  module AlacrityRails
2
- VERSION = '0.8.0'
2
+ VERSION = '0.8.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alacrity-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alacrity, LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails