red_cross 0.2.4 → 0.2.5

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: 74b7e78f8ab3f2eb3aa38cf5c1b1a82aafbab5b8
4
- data.tar.gz: 2f5ab0fb9befc1a72a717e53b842f128950f8c14
3
+ metadata.gz: ac7909151c96e69e0a1e63fe749754b3bfd23a8d
4
+ data.tar.gz: 606e950ecbc33ef42b0a4c5c61b5d9c9d852cf6b
5
5
  SHA512:
6
- metadata.gz: 0e1c052a905c0589e55ee11b28626d044deab1135066f314fc25b3bb1a50ef36918fa26a355ca9629c8d9f5ede73567022e51744bf0e7c3a6188c7a5b81a3437
7
- data.tar.gz: 3eb72066be6d21672d57e79684abd37fb5a08d6be80fcefaae2dc5489f75383770df3ff66af1fced2701895651c0fcdb46ce27a7555d7244adcae56ec071e543
6
+ metadata.gz: 7a822c815d8c19593e844f2e20c9fdf93b75253a19fdc366471cab5fd3fdef0190b23a66d9e60f3ba8335209fbb22011762311e29ba847753f180f07228fdef7
7
+ data.tar.gz: 6c40830957e91da09b2c818c1f75a82ede946ca7a1bc95a5bc8a62c5b31d167e15db551ccefed09f10a28564d4fc090daa78df2289e23ad6a8fca788d7683b1f
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # RedCross
2
2
 
3
3
  This Gem reports events to segment - to be added:
4
- Sending events to an event collector which will use Kafka
4
+ Sending events to an eventbus
5
5
 
6
6
  ## Installation
7
7
 
@@ -1,7 +1,7 @@
1
1
  module RedCross
2
2
  module Trackers
3
3
  class HttpTracker < RedCross::Trackers::Base
4
- class FailedPushingToKafka < Exception
4
+ class FailedPushingToEventbus < Exception
5
5
  def initialize(code, route, return_code)
6
6
  @code = code
7
7
  @route = route
@@ -9,17 +9,17 @@ module RedCross
9
9
  end
10
10
 
11
11
  def to_s
12
- "Failed pushing to Kafka. Error code: #{@code}, route: #{@route} Error: #{@return_code.to_s}"
12
+ "Failed pushing to Eventbus. Error code: #{@code}, route: #{@route} Error: #{@return_code.to_s}"
13
13
  end
14
14
  end
15
- attr_accessor :clerk_host
15
+ attr_accessor :eventbus_host
16
16
 
17
17
  def initialize(host)
18
- @clerk_host = host
18
+ @eventbus_host = host
19
19
  end
20
20
 
21
- def track(attrs, additional_args = {})
22
- clerk_request(@clerk_host,attrs.merge(additional_args), :post)
21
+ def track(route, attrs, additional_args = {})
22
+ eventbus_request(@eventbus_host + route, attrs.merge(additional_args), :post)
23
23
  end
24
24
 
25
25
  def identify(attrs, additional_args = {})
@@ -30,7 +30,7 @@ module RedCross
30
30
  {}
31
31
  end
32
32
 
33
- def clerk_request(request_url, params, method = :get)
33
+ def eventbus_request(request_url, params, method = :get)
34
34
  request = Typhoeus::Request.new(
35
35
  request_url,
36
36
  method: method,
@@ -41,7 +41,7 @@ module RedCross
41
41
  if response.success?
42
42
  return true
43
43
  else
44
- raise FailedPushingToKafka.new(response.response_code ,request_url, response.return_code)
44
+ raise FailedPushingToEventbus.new(response.response_code ,request_url, response.return_code)
45
45
  end
46
46
  end
47
47
  request.run
@@ -3,8 +3,7 @@ module RedCross
3
3
  class MonitorTracker < RedCross::Trackers::Base
4
4
  attr_accessor :client
5
5
 
6
- def initialize(database = '', host = '', port = '')
7
- [database, host, port].each{ |var| return if !var.is_a?(String) || var.empty? }
6
+ def initialize(database = 'test', host = 'localhost', port = 8086)
8
7
  @client = InfluxDB::Client.new database,
9
8
  host: host,
10
9
  port: port,
@@ -1,3 +1,3 @@
1
1
  module RedCross
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/lib/red_cross.rb CHANGED
@@ -2,6 +2,7 @@ require 'red_cross/version'
2
2
  require 'red_cross/configuration'
3
3
  require 'segment'
4
4
  require 'typhoeus'
5
+ require 'resque/plugins/red_cross_async'
5
6
  require 'resque'
6
7
  require 'influxdb'
7
8
  require 'red_cross/logger'
@@ -0,0 +1,30 @@
1
+ module Resque
2
+ module Plugins
3
+ module RedCrossAsync
4
+ # Hash of properties for RedCross.monitor
5
+ # Please add count: MY_NUMBER in case your metric value differs 1
6
+ def properties(*args)
7
+ {}
8
+ end
9
+
10
+ def after_perform_actions(*args)
11
+ RedCross.flush
12
+ send_metrics('performed', *args)
13
+ end
14
+
15
+ def before_perform_send_monitor_data(*args)
16
+ send_metrics('before_perform', *args)
17
+ end
18
+
19
+ def on_failure_send_monitor_data(e, *args)
20
+ send_metrics('failed', *args)
21
+ end
22
+
23
+ private
24
+
25
+ def send_metrics(event_type, *args)
26
+ RedCross.monitor_track(event: 'resque_job_' + event_type, properties: { class: self.name }.merge(properties(*args)))
27
+ end
28
+ end
29
+ end
30
+ 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.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronbarab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-19 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: analytics-ruby
@@ -115,13 +115,12 @@ files:
115
115
  - lib/red_cross.rb
116
116
  - lib/red_cross/configuration.rb
117
117
  - lib/red_cross/logger.rb
118
- - lib/red_cross/resque/plugins/red_cross_monitor.rb
119
- - lib/red_cross/resque/scheduler.rb
120
118
  - lib/red_cross/trackers/base.rb
121
119
  - lib/red_cross/trackers/http_tracker.rb
122
120
  - lib/red_cross/trackers/monitor_tracker.rb
123
121
  - lib/red_cross/trackers/segment_tracker.rb
124
122
  - lib/red_cross/version.rb
123
+ - lib/resque/plugins/red_cross_monitor.rb
125
124
  - red_cross.gemspec
126
125
  homepage: https://github.com/YotpoLtd
127
126
  licenses:
@@ -1,65 +0,0 @@
1
- module Resque
2
- module Plugins
3
- module RedCrossMonitor
4
- # Hash of properties for RedCross.monitor
5
- # Please add count: MY_NUMBER in case your metric value differs 1
6
- def job_method(*args)
7
- #Add the method that triggered by the job
8
- 'no_job_method'
9
- end
10
-
11
- def before_schedule_send_monitor_data(*args)
12
- send_metrics('before_schedule', *args)
13
- end
14
-
15
- def after_schedule_send_monitor_data(*args)
16
- send_metrics('after_schedule', *args)
17
- end
18
-
19
- def before_delayed_enqueue_send_monitor_data(*args)
20
- send_metrics('before_delayed_enqueue', *args)
21
- end
22
-
23
- def before_enqueue_send_monitor_data(*args)
24
- send_metrics('before_enqueue', *args)
25
- end
26
-
27
- def after_enqueue_send_monitor_data(*args)
28
- send_metrics('after_enqueue', *args)
29
- end
30
-
31
- def before_perform_send_monitor_data(*args)
32
- @job_start_time = Time.now()
33
- send_metrics('before_perform', *args)
34
- end
35
-
36
- def after_perform_actions(*args)
37
- ::RedCross.flush
38
- @job_end_time = Time.now()
39
- send_metrics('performed', *args)
40
- end
41
-
42
- def on_failure_send_monitor_data(e, *args)
43
- @job_end_time = Time.now()
44
- send_metrics('failed', *args)
45
- end
46
-
47
- def default_event_properties(*args)
48
- @event_properties ||= { fields: { } }
49
- @event_properties[:class] ||= self.name
50
- event_job_method = @event_properties[:event_method].nil? ? job_method(*args) : @event_properties[:event_method]
51
- if (!event_job_method.nil? && ([String, Integer, Symbol].include? event_job_method.class))
52
- @event_properties[:event_method] = event_job_method
53
- else
54
- @event_properties[:event_method] = 'no_valid_job_method'
55
- end
56
- end
57
-
58
- def send_metrics(job_status, *args)
59
- default_event_properties(*args)
60
- @event_properties[:fields][:run_time] = ((@job_end_time - @job_start_time)*1000).to_i if %w(performed failed).include? job_status
61
- ::RedCross.monitor_track(event: 'resque', properties: @event_properties.merge({ job_status: job_status }))
62
- end
63
- end
64
- end
65
- end
@@ -1,15 +0,0 @@
1
- module Resque
2
- module Scheduler
3
- module DelayingExtensions
4
- alias default_last_enqueued_at last_enqueued_at
5
- def last_enqueued_at(name, timestemp)
6
- properties = {
7
- task_name: name,
8
- status: 'enqueued'
9
- }
10
- RedCross.monitor_track(event: 'resque_scheduler', properties: properties)
11
- default_last_enqueued_at(name, timestemp)
12
- end
13
- end
14
- end
15
- end