subexec-notifications 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ gemfiles/*
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,12 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ install:
5
+ - gem install bundler
6
+ - gem install rake
7
+ - gem install appraisal
8
+ before_script:
9
+ - bundle install
10
+ - rake appraisal:setup
11
+ script:
12
+ - rake appraisal test
@@ -0,0 +1,16 @@
1
+
2
+ appraise 'v30' do
3
+ gem 'activesupport', '~> 3.0.0'
4
+ end
5
+
6
+ appraise 'v31' do
7
+ gem 'activesupport', '~> 3.1.0'
8
+ end
9
+
10
+ appraise 'v32' do
11
+ gem 'activesupport', '~> 3.2.0'
12
+ end
13
+
14
+ appraise 'v40' do
15
+ gem 'activesupport', '~> 4.0.0'
16
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'ruby_gntp', require: false
6
+
@@ -0,0 +1,6 @@
1
+
2
+ guard 'minitest' do
3
+ watch(%r|^lib/.*|) { "test/cases" }
4
+ watch(%r|^test/test_helper\.rb|) { "test/cases" }
5
+ watch(%r|^test/cases/(.*)_test\.rb|)
6
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ken Collins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Subexec::Notifications
2
+
3
+ Instrumentation for [`Subexec`](https://github.com/nulayer/subexec) commands using `ActiveSupport::Notifications`.
4
+
5
+
6
+ ## Usage
7
+
8
+ Read the full document documentation for [`ActiveSupport::Notifications`](http://apidock.com/rails/ActiveSupport/Notifications) first. All `Subexec` events can be subscribed to using the `subexec.run` key.
9
+
10
+ ```ruby
11
+ ActiveSupport::Notifications.subscribe('subexec.run') do |*args|
12
+ Subscribers::SubexecLibrato.new(*args)
13
+ end
14
+ ```
15
+
16
+ The payload for events return the `Subexec` instance via the `:sub` key as well as the hostname of the machine running the command via the `:hostname` key. For example:
17
+
18
+ ```ruby
19
+ module Subscribers
20
+ class SubexecLibrato < Base
21
+
22
+ def initialize(*args)
23
+ @event = ActiveSupport::Notifications::Event.new(*args)
24
+ process
25
+ end
26
+
27
+ def process
28
+ sub = @event.payload[:sub]
29
+ duration = @event.duration
30
+ command = sub.command.split.first
31
+ source = @event.payload[:hostname]
32
+ Librato::Metrics.submit 'subexec:run' => {type: command, value: duration, source: source}
33
+ end
34
+
35
+ end
36
+ end
37
+ ```
38
+
39
+
40
+ ## Learn More
41
+
42
+ * [Digging Deep with ActiveSupport::Notifications](https://speakerdeck.com/nextmat/digging-deep-with-activesupportnotifications)
43
+
44
+
45
+ ## Contributing
46
+
47
+ The subexec-notifications gem is tested against ActiveSupport v3.x to v4.x. We run our tests on [Travis CI](http://travis-ci.org/customink/subexec-notifications) in both Ruby 1.9 and 2.0. Check the `.travis.yml` file for the latest build information.
48
+
49
+ If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite.
50
+
51
+ ```shell
52
+ $ bundle install
53
+ $ bundle exec rake appraisal:setup
54
+ $ bundle exec rake appraisal test
55
+ ```
56
+
57
+ We use the [appraisal](https://github.com/thoughtbot/appraisal) gem from Thoughtbot to help us generate the individual gemfiles for each ActiveSupport version and to run the tests locally against each generated Gemfile. The `rake appraisal test` command actually runs our test suite against all ActiveSupport versions in our `Appraisal` file. If you want to run the tests for a specific ActiveSupport version, use `rake -T` for a list. For example, the following command will run the tests for ActiveSupport v3.2 only.
58
+
59
+ ```shell
60
+ $ bundle exec rake appraisal:v32 test
61
+ ```
62
+
63
+ Our current build status is:
64
+ [![Build Status](https://travis-ci.org/customink/subexec-notifications.png?branch=master)](https://travis-ci.org/customink/subexec-notifications)
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'appraisal'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs = ['lib','test']
7
+ t.test_files = Dir.glob('test/**/*_test.rb').sort
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
12
+
13
+ desc "Setup Appraisal."
14
+ task 'appraisal:setup' do
15
+ Rake::Task['appraisal:cleanup'].invoke
16
+ Rake::Task['appraisal:gemfiles'].invoke
17
+ Rake::Task['appraisal:install'].invoke
18
+ end
@@ -0,0 +1 @@
1
+ require 'subexec/notifications'
@@ -0,0 +1,12 @@
1
+ require 'socket'
2
+ require 'subexec'
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext/module/aliasing'
5
+ require 'active_support/notifications'
6
+ require 'subexec/notifications/version'
7
+ require 'subexec/notifications/extensions'
8
+
9
+ class Subexec
10
+ module Notifications
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ class Subexec
2
+ module Notifications
3
+ module Extensions
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ alias_method_chain :run!, :notifications
9
+ end
10
+
11
+ def run_with_notifications!
12
+ ActiveSupport::Notifications.instrument "subexec.run", notification_payload do
13
+ run_without_notifications!
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def notification_payload
20
+ { sub: self, hostname: Socket.gethostname }
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ Subexec.send :include, Subexec::Notifications::Extensions
@@ -0,0 +1,5 @@
1
+ class Subexec
2
+ module Notifications
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'subexec/notifications/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'subexec-notifications'
7
+ spec.version = Subexec::Notifications::VERSION
8
+ spec.authors = ['Ken Collins']
9
+ spec.email = ['ken@metaskills.net']
10
+ spec.summary = 'Instrumentation for Subexec commands using ActiveSupport::Notifications'
11
+ spec.description = spec.summary
12
+ spec.homepage = 'http://github.com/customink/subexec-notifications'
13
+ spec.license = 'MIT'
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+ spec.add_runtime_dependency 'subexec'
19
+ spec.add_runtime_dependency 'activesupport', '>= 3.0'
20
+ spec.add_development_dependency 'appraisal'
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'minitest'
23
+ spec.add_development_dependency 'guard-minitest'
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class Subexec
4
+ module Notifications
5
+ class NotificationsTest < TestCase
6
+
7
+ it 'runs a basic command' do
8
+ sub = Subexec.run "echo 'hello'"
9
+ sub.timeout.must_be_instance_of Fixnum
10
+ sub.exitstatus.must_equal 0
11
+ sub.pid.must_be_instance_of Fixnum
12
+ sub.output.must_equal "hello\n"
13
+ sub.command.must_equal "echo 'hello'"
14
+ sub.lang.must_equal "C"
15
+ end
16
+
17
+ it 'instrements events' do
18
+ subscribed { Subexec.run "echo 'hello'" }
19
+ event.name.must_equal 'subexec.run'
20
+ event.duration.must_be_close_to 15, 30
21
+ event.payload.must_be_instance_of Hash
22
+ end
23
+
24
+ it 'payload includes the Subexec object' do
25
+ subscribed { Subexec.run "echo 'Subexec Object'" }
26
+ sub = event.payload[:sub]
27
+ sub.must_be_instance_of Subexec
28
+ sub.command.must_equal "echo 'Subexec Object'"
29
+ sub.exitstatus.must_equal 0
30
+ end
31
+
32
+ it 'payload includes the hostname' do
33
+ Socket.stub :gethostname, 'vm22.bigcompany.com' do
34
+ subscribed { Subexec.run "echo 'Important Work'" }
35
+ event.payload[:hostname].must_equal 'vm22.bigcompany.com'
36
+ end
37
+ end
38
+
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ require 'bundler' ; Bundler.require :development, :test
2
+ require 'subexec-notifications'
3
+ require 'minitest/spec'
4
+ require 'minitest/mock'
5
+ require 'minitest/autorun'
6
+
7
+ class Subexec
8
+ module Notifications
9
+ class TestCase < MiniTest::Spec
10
+
11
+ let(:callback) { lambda { |*args| event(*args) } }
12
+
13
+ after do
14
+ clear_event!
15
+ end
16
+
17
+
18
+ private
19
+
20
+ def subscribed(name="subexec.run")
21
+ subscriber = ActiveSupport::Notifications.subscribe(name, &callback)
22
+ yield
23
+ ensure
24
+ ActiveSupport::Notifications.unsubscribe(subscriber)
25
+ end
26
+
27
+ def event(*args)
28
+ @event ||= ActiveSupport::Notifications::Event.new(*args)
29
+ end
30
+
31
+ def clear_event!
32
+ @event = nil
33
+ end
34
+
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subexec-notifications
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Ken Collins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: subexec
16
+ type: :runtime
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ none: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ none: false
29
+ prerelease: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ type: :runtime
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
38
+ none: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ none: false
45
+ prerelease: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: appraisal
48
+ type: :development
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ none: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ none: false
61
+ prerelease: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ type: :development
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ none: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ none: false
77
+ prerelease: false
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ type: :development
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ none: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ none: false
93
+ prerelease: false
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-minitest
96
+ type: :development
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ none: false
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ none: false
109
+ prerelease: false
110
+ - !ruby/object:Gem::Dependency
111
+ name: rake
112
+ type: :development
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ none: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ none: false
125
+ prerelease: false
126
+ description: Instrumentation for Subexec commands using ActiveSupport::Notifications
127
+ email:
128
+ - ken@metaskills.net
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .travis.yml
135
+ - Appraisals
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - lib/subexec-notifications.rb
142
+ - lib/subexec/notifications.rb
143
+ - lib/subexec/notifications/extensions.rb
144
+ - lib/subexec/notifications/version.rb
145
+ - subexec-notifications.gemspec
146
+ - test/cases/notifications_test.rb
147
+ - test/test_helper.rb
148
+ homepage: http://github.com/customink/subexec-notifications
149
+ licenses:
150
+ - MIT
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ segments:
160
+ - 0
161
+ hash: 1852404599446323047
162
+ version: '0'
163
+ none: false
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ segments:
169
+ - 0
170
+ hash: 1852404599446323047
171
+ version: '0'
172
+ none: false
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 1.8.25
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: Instrumentation for Subexec commands using ActiveSupport::Notifications
179
+ test_files:
180
+ - test/cases/notifications_test.rb
181
+ - test/test_helper.rb