red_cross 0.2.14 → 0.2.15

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: 4e4b4f06dcded53b8790298ea43dee10c413b3dd
4
- data.tar.gz: 90d0a731c01730e2cdb90579faca4ce04d474923
3
+ metadata.gz: daa8a11872bc4bc51250785df23512137156f604
4
+ data.tar.gz: f2a690c66d17f6f474704310b6c190f992696129
5
5
  SHA512:
6
- metadata.gz: 96cf40eb35b443ed47b96eb376a709377cb506ce69e853ee898ac1ebd3441fc5b328185391af90abeb281f5f99ede562e87259955bab525f354d8702ded25c55
7
- data.tar.gz: caa5f4ff5d91def610a390f7800622e0440b3fa230d79116df100311acb65669a18c4e016425a6e8b1a5d1e2a8a236a22f87ad207dc989f8c9b592b20553e02b
6
+ metadata.gz: 0e01f87ad61306a8d8e6550c0a49000e95983365c7cd6dfe69457afd2ae144a7f0b20a2cc6d04d10153bc1a1ed96be56ae27895f5adccd92a2b9f82fe55556e2
7
+ data.tar.gz: 4c20a2d88b7607bc6bb616e00b46d628a3552ee37520bbca12a6b56c5fe7cd9dc917b961799e9cb4efacf48010d0632e096531ef5c4a8f889822b2a1da526f9d
@@ -29,40 +29,39 @@ module Resque
29
29
  end
30
30
 
31
31
  def before_perform_send_monitor_data(*args)
32
- @job_start_time = Time.now()
32
+ @red_cross_job_start_time = Time.now()
33
33
  send_metrics('before_perform', *args)
34
34
  end
35
35
 
36
36
  def after_perform_actions(*args)
37
37
  ::RedCross.flush
38
- @job_end_time = Time.now()
38
+ @red_cross_job_end_time = Time.now()
39
39
  send_metrics('performed', *args)
40
40
  end
41
41
 
42
- def on_failure_send_monitor_data(*args)
43
- @job_end_time = Time.now()
42
+ def on_failure_send_monitor_data(e, *args)
43
+ @red_cross_job_end_time = Time.now()
44
44
  send_metrics('failed', *args)
45
45
  end
46
46
 
47
47
  def default_event_properties(*args)
48
- @event_properties ||= { fields: { } }
49
- @event_properties[:class] ||= self.name
50
- @event_properties[:queue] ||= Resque.queue_from_class(self)
48
+ event_properties = { class: self.name, fields: { } }
49
+ event_properties[:exception] = args.shift.class.to_s if args.is_a?(Array) && args[0].is_a?(Exception)
50
+ queue = Resque.queue_from_class(self)
51
+ (queue && !queue.to_s.empty?) ? event_properties[:queue] = queue : event_properties[:class]
51
52
  event_job_method = job_method(*args)
52
53
  if (!event_job_method.nil? && ([String, Integer, Symbol].include? event_job_method.class))
53
- @event_properties[:event_method] = event_job_method
54
+ event_properties[:event_method] = event_job_method
54
55
  else
55
- @event_properties[:event_method] = 'no_valid_job_method'
56
+ event_properties[:event_method] = 'no_valid_job_method'
56
57
  end
58
+ event_properties
57
59
  end
58
60
 
59
61
  def send_metrics(job_status, *args)
60
- default_event_properties(*args)
61
- @event_properties[:fields][:run_time] = ((@job_end_time - @job_start_time)*1000).to_i if %w(performed failed).include? job_status
62
- if args.is_a?(Array) && args[0].is_a?(Exception)
63
- @event_properties[:exception] = args.shift.class.to_s
64
- end
65
- ::RedCross.monitor_track(event: 'resque', properties: @event_properties.merge({ job_status: job_status }))
62
+ event_properties = default_event_properties(*args)
63
+ event_properties[:fields][:run_time] = ((@red_cross_job_end_time - @red_cross_job_start_time)*1000).to_i if %w(performed failed).include? job_status
64
+ ::RedCross.monitor_track(event: 'resque', properties: event_properties.merge({ job_status: job_status }))
66
65
  end
67
66
  end
68
67
  end
@@ -32,7 +32,7 @@ module RedCross
32
32
  properties = attrs[:properties] || {}
33
33
  values = { count: 1 }.merge((properties.delete(:fields) || {}))
34
34
  begin
35
- client.write_point(event, { values: values, tags: properties })
35
+ client.write_point(event, { values: compact(values), tags: compact(properties) })
36
36
  client.writer.worker.stop!
37
37
  rescue => e
38
38
  error_data = {
@@ -51,6 +51,10 @@ module RedCross
51
51
  log :error, error_data
52
52
  end
53
53
  end
54
+
55
+ def compact(hash)
56
+ hash.respond_to?(:compact) ? hash.compact : hash.delete_if {|k,v| v == nil }
57
+ end
54
58
  end
55
59
  end
56
60
  end
@@ -1,3 +1,3 @@
1
1
  module RedCross
2
- VERSION = '0.2.14'
2
+ VERSION = '0.2.15'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_cross
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronbarab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: analytics-ruby