resque-cloudwatch-monitor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MWFiOTU4M2EzMGZlMzg2YzdhNDgyNTc1NzBkOGQ2MTlhMjhlZGFlMg==
5
+ data.tar.gz: !binary |-
6
+ NTU3NTY0OWNjODUyNjNkNTllOTY2ZGE1MGFhZTZmYTIzMTY3MDk3MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ODIxYzNiNTM2OTVmYzAzMWJkOTljODBmODY1ZDc4YTdkNTkyYzkzNGI3MmZj
10
+ ZjMyOWU0Y2FhNjM5NWZkYzk5NDQ4YjE3NmU3ZDkwNzRjMGYwNWMwMjU5ZjA2
11
+ YTU5ODhlYzFjODQ5OTdjMWZmOWYzMTUxMjcyNTAwYmVjM2NkMjY=
12
+ data.tar.gz: !binary |-
13
+ OTA5NjZhMDcyYjAzYWY4MmI5NjQyMzgzNDNlMWRjOTgxZTc0YjU1MThiZGM1
14
+ NzU3OWQxMWQyYWE5ODhhYjgyNmMwZjRhM2ZjMjg2MWFmMzczMzcyMWRhNzMz
15
+ YzdiZGJiY2VjNzI5ZDUzYmFjMWE0OWY0OWZhNjkzNWI2NmY5OWM=
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Yotpo Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ resque-cloudwatch-monitor
2
+ ============
3
+
4
+ A [Resque][rq] plugin. Requires Resque ~> 1.25
5
+
6
+ This gem provides Cloudwatch reports of failed Resque jobs
7
+
8
+ * Redis backed retry count/limit.
9
+
10
+
11
+ Install & Quick Start
12
+ ---------------------
13
+
14
+ To install:
15
+
16
+ $ gem install resque-cloudwatch-monitor
17
+
18
+ If you're using [Bundler][bundler] to manage your dependencies, you should add `gem
19
+ 'resque-cloudwatch-monitor'` to your projects `Gemfile`.
20
+
21
+
22
+ Use the plugin:
@@ -0,0 +1,5 @@
1
+ require 'resque'
2
+
3
+ require 'resque/plugins/cloudwatch-monitor/cloudwatch-monitor'
4
+ require 'resque/plugins/cloudwatch-monitor/configuration'
5
+ require 'resque/plugins/cloudwatch-monitor/version'
@@ -0,0 +1,56 @@
1
+ module Resque
2
+ module Plugins
3
+
4
+ module CloudwatchMonitor
5
+
6
+ #Cloudwatch Custom Metric Namespace
7
+ def namespace
8
+ Configuration.namespace
9
+ end
10
+
11
+ #Cloudwatch metric name
12
+ def metric_name
13
+ @queue || queue
14
+ end
15
+
16
+ #Array of dimensions for Cloudwatch
17
+ def dimensions(*args)
18
+ []
19
+ end
20
+
21
+ #Metric timestamp
22
+ def timestamp
23
+ Time.now.iso8601
24
+ end
25
+
26
+ #Cloudwatch metric unit type
27
+ def unit
28
+ 'Count'
29
+ end
30
+
31
+ #Cloudwatch metric value
32
+ def value
33
+ 1
34
+ end
35
+
36
+ #Job on failure hook. receives the job arguments and the exception
37
+ def on_failure(e, *args)
38
+
39
+ dimensions = dimensions(*args)
40
+
41
+ metric_data = {
42
+ metric_name: metric_name.to_s,
43
+ dimensions: dimensions,
44
+ timestamp: timestamp,
45
+ value: value,
46
+ unit: unit.to_s
47
+ }
48
+
49
+ #Send to metrics. One general of the queue and another one with dimensions if custom dimensions
50
+ metrics_to_send = dimensions.empty? ? [metric_data] : [metric_data, metric_data.merge(dimensions: [])]
51
+
52
+ Configuration.cloudwatch_client.put_metric_data(namespace: namespace, metric_data: metrics_to_send)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,16 @@
1
+ module Resque
2
+ module Plugins
3
+ module CloudwatchMonitor
4
+ module Configuration
5
+ class << self
6
+
7
+ attr_accessor :namespace, :cloudwatch_client
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module Resque
2
+ module Plugins
3
+ module CloudwatchMonitor
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'resque/plugins/cloudwatch-monitor/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'resque-cloudwatch-monitor'
5
+ s.version = Resque::Plugins::CloudwatchMonitor::VERSION
6
+ s.date = Time.now.strftime('%Y-%m-%d')
7
+ s.summary = 'Send Resque Failures To AWS CloudWatch'
8
+ s.email = 'avichay@yotpo.com'
9
+ s.homepage = 'https://github.com/YotpoLtd/resque-cloudwatch-monitor'
10
+ s.description = 'Allows reporting failures of resque jobs to Amazon CloudWatch'
11
+ s.has_rdoc = false
12
+ s.require_paths = ['lib']
13
+ s.authors = ['Yotpo/avichay@yotpo']
14
+ s.files = ['README.md', 'resque-cloudwatch-monitor.gemspec', 'LICENSE']
15
+ s.files += Dir['**/*.rb']
16
+ s.license = 'MIT'
17
+
18
+ s.add_dependency 'resque', '~> 1.25'
19
+ s.add_development_dependency 'rake', '~> 10.3'
20
+ s.add_development_dependency 'aws-sdk', '~> 1.11.1'
21
+ s.add_development_dependency 'rspec', '~> 3.3.0'
22
+ s.add_development_dependency 'timecop', '~> 0.7.4'
23
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ describe Resque::Plugins::CloudwatchMonitor do
3
+
4
+ before(:all) do
5
+ Resque.redis.flushall
6
+ @worker = Resque::Worker.new('*')
7
+ @worker.register_worker
8
+
9
+ Timecop.freeze(Time.now)
10
+
11
+ @metric_data = {
12
+ metric_name: 'Failure',
13
+ dimensions: [],
14
+ timestamp: Time.now.iso8601,
15
+ value: 1,
16
+ unit: 'Count'
17
+ }
18
+
19
+ end
20
+
21
+ after(:all) do
22
+ Timecop.return
23
+ end
24
+
25
+ it 'failure in resque job sends metric to cloudwatch' do
26
+ expect(Resque::Plugins::CloudwatchMonitor::Configuration.cloudwatch_client).
27
+ to receive(:put_metric_data).
28
+ with(namespace: 'Resque Failures', metric_data: [@metric_data])
29
+
30
+ Resque.enqueue(FailureJobTest, :fail)
31
+ CloudWatchMonitorTest.perform_enqueued_job(@worker)
32
+ end
33
+
34
+ it 'failure in resque job sends custom dimensions' do
35
+ class FailureJobTest
36
+ def self.dimensions(*args)
37
+ [{name: 'Custom', value: args.first.to_s}]
38
+ end
39
+ end
40
+
41
+ # allow(FailureJobTest).to receive(:dimensions) {[{name: 'Custom', value: 'fail'}] }
42
+
43
+ expect(Resque::Plugins::CloudwatchMonitor::Configuration.cloudwatch_client).
44
+ to receive(:put_metric_data).
45
+ with(namespace: 'Resque Failures', metric_data: [@metric_data.merge(dimensions: [{name: 'Custom', value: 'fail'}]), @metric_data])
46
+
47
+ Resque.enqueue(FailureJobTest, :fail)
48
+ CloudWatchMonitorTest.perform_enqueued_job(@worker)
49
+ end
50
+
51
+ it 'successful job does not send a metric to cloudwatch' do
52
+ expect(Resque::Plugins::CloudwatchMonitor::Configuration.cloudwatch_client).
53
+ to receive(:put_metric_data).
54
+ exactly(0).times
55
+
56
+ Resque.enqueue(SuccessJobTest, :success)
57
+ CloudWatchMonitorTest.perform_enqueued_job(@worker)
58
+ end
59
+ end
@@ -0,0 +1,38 @@
1
+ require 'aws'
2
+ require 'timecop'
3
+ require 'resque-cloudwatch-monitor'
4
+
5
+ RSpec.configure do |config|
6
+ # some (optional) config here
7
+ end
8
+
9
+ class CloudWatchMonitorTest
10
+ def self.perform_enqueued_job(worker)
11
+ job = worker.reserve
12
+ worker.perform(job)
13
+ worker.done_working
14
+ end
15
+ end
16
+
17
+ Resque::Plugins::CloudwatchMonitor::Configuration.configure do |config|
18
+ config.namespace = 'Resque Failures'
19
+ config.cloudwatch_client = AWS::CloudWatch::Client.new
20
+ end
21
+
22
+ class FailureJobTest
23
+ extend Resque::Plugins::CloudwatchMonitor
24
+ @queue = 'Failure'
25
+
26
+ def self.perform(*args)
27
+ raise Exception.new('Test Error')
28
+ end
29
+ end
30
+
31
+ class SuccessJobTest
32
+ extend Resque::Plugins::CloudwatchMonitor
33
+ @queue = 'Success'
34
+
35
+ def self.perform(*args)
36
+ 1 + 1
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-cloudwatch-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yotpo/avichay@yotpo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: resque
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.25'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.25'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.11.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.11.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.7.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.7.4
83
+ description: Allows reporting failures of resque jobs to Amazon CloudWatch
84
+ email: avichay@yotpo.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE
90
+ - README.md
91
+ - lib/resque-cloudwatch-monitor.rb
92
+ - lib/resque/plugins/cloudwatch-monitor/cloudwatch-monitor.rb
93
+ - lib/resque/plugins/cloudwatch-monitor/configuration.rb
94
+ - lib/resque/plugins/cloudwatch-monitor/version.rb
95
+ - resque-cloudwatch-monitor.gemspec
96
+ - spec/cloudwatch_monitor_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/YotpoLtd/resque-cloudwatch-monitor
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Send Resque Failures To AWS CloudWatch
122
+ test_files: []