percy-common 1.1.0 → 1.2.0

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: 3d5a79133a1c95ae793cb30e7135badb17b59db1
4
- data.tar.gz: 1c4a63b4f4998e03f4500b99212e6968b565a7c1
3
+ metadata.gz: a652130076a2b0813f00bb165c51b299824510bc
4
+ data.tar.gz: 9fb9173c1160f0ce954d90fd28c58b00aa1e027f
5
5
  SHA512:
6
- metadata.gz: b2efd0479f2da30ff271cd09376a9910055f1d381b9538a6808939e3e1313130aa344370b076e2585e432f73a541cf04b5cb3b8818a961e08b26ecbe603a3f27
7
- data.tar.gz: a2205abeed0c19bad7669d6bccd840c16242d3b9bd966cff4a5683ab1347a14dde8abb5288ddae44f572665d96930bf2ac05264bb65c72e2e0122893f09a9b6e
6
+ metadata.gz: 508907f4ae23369340fd5f34a03dbf98c2b51eb12fcf0931575b1c8fa9d506525fa502939ba46bf48c8cbc2ffe51d9fab8f8a62a80b770b54a9d33fa2b1385f8
7
+ data.tar.gz: f06831d5d30151b47fa2c60f98cd520e4a036845a7a52c2ad98e27e900a00bab568e8b70bbe0ba382eee97aa15d1f2e873c3b325d20e350e66ab18bff46bb06e
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --color
2
1
  --require spec_helper
2
+ --color
3
3
  --format d
@@ -0,0 +1,7 @@
1
+ inherit_gem:
2
+ percy-style:
3
+ - default.yml
4
+
5
+ RSpec/DescribeClass:
6
+ Exclude:
7
+ - spec/percy/logger_spec.rb
@@ -2,8 +2,10 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.2.2
5
+ - 2.2.5
6
6
  - ruby-head
7
7
  before_install:
8
8
  - gem update bundler
9
- script: bundle exec rspec
9
+ script:
10
+ - bundle exec rubocop -D
11
+ - bundle exec rspec
@@ -0,0 +1,16 @@
1
+ # More info at https://github.com/guard/guard#readme
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/README.md CHANGED
@@ -1,3 +1,99 @@
1
1
  # percy-common
2
2
 
3
3
  Server-side common library for Percy.
4
+
5
+ ## Percy::KeywordStruct
6
+
7
+ A simple struct that can be used when you need to return a simple value object.
8
+
9
+ ```ruby
10
+ require 'percy/keyword_struct'
11
+
12
+ class Foo < Percy::KeywordStruct.new(:bar, :baz, :qux)
13
+ end
14
+
15
+ foo = Foo.new(bar: 123, baz: true)
16
+ foo.bar # --> 123
17
+ foo.baz # --> true
18
+ foo.qux # --> nil
19
+ foo.fake # --> raises NoMethodError
20
+ ```
21
+
22
+ ## Percy.logger
23
+
24
+ ```ruby
25
+ require 'percy/logger'
26
+
27
+ Percy.logger.debug { 'debug log' }
28
+ Percy.logger.info { 'info log' }
29
+ Percy.logger.warn { 'warning log' }
30
+ Percy.logger.error { 'error message' }
31
+ ```
32
+
33
+ Prefer the block form usage `Percy.logger.debug { 'message' }` over `Percy.logger.debug('message')` because it is slightly more efficient when the log will be excluded by the current logging level. For example, if the log level is currently `info`, then a `debug` log in block form will never evaluate or allocate the message string itself.
34
+
35
+ ## Percy::ProcessHelpers
36
+
37
+ ### `gracefully_kill(pid[, grace_period_seconds: 10])`
38
+
39
+ Returns `true` if the process was successfully killed, or `false` if the process did not exist or its exit status was already collected.
40
+
41
+ ```ruby
42
+ require 'percy/process_helpers'
43
+
44
+ Percy::ProcessHelpers.gracefully_kill(pid)
45
+ ```
46
+
47
+ This will send `SIGTERM` to the process, wait up to 10 seconds, then send `SIGKILL` if it has not already shut down.
48
+
49
+ ## Percy::Stats
50
+
51
+ Client for recording Datadog metrics and automatically setting up Percy-specific environment tags.
52
+
53
+ This class is a wrapper for [Datadog::Statsd](https://github.com/DataDog/dogstatsd-ruby), an extended client for DogStatsD, which extends the StatsD metric server for Datadog.
54
+
55
+ Basic usage includes:
56
+
57
+ ```ruby
58
+ require 'percy/stats'
59
+
60
+ stats = Percy::Stats.new
61
+
62
+ # Increment a counter.
63
+ stats.increment('page.views')
64
+
65
+ # Record a gauge 50% of the time.
66
+ stats.gauge('users.online', 123, sample_rate: 0.5)
67
+
68
+ # Sample a histogram.
69
+ stats.histogram('file.upload.size', 1234)
70
+
71
+ # Time a block of code.
72
+ stats.time('page.render') do
73
+ render_page('home.html')
74
+ end
75
+
76
+ # Send several metrics at the same time.
77
+ # All metrics will be buffered and sent in one packet when the block completes.
78
+ stats.batch do |s|
79
+ s.increment('page.views')
80
+ s.gauge('users.online', 123)
81
+ end
82
+
83
+ # Tag a metric.
84
+ stats.histogram('query.time', 10, tags: ['version:1'])
85
+ ```
86
+
87
+ See the [Datadog::Statsd](https://github.com/DataDog/dogstatsd-ruby) docs for more usage.
88
+
89
+ Our wrapper adds support for a non-block based `start_timing` and `stop_timing` methods:
90
+
91
+ ```ruby
92
+ require 'percy/stats'
93
+
94
+ stats = Percy::Stats.new
95
+
96
+ stats.start_timing
97
+ account.activate!
98
+ stats.stop_timing('account.activate')
99
+ ```
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Common
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ # A struct that only allows keyword arguments.
2
+ # For example, this should be used to create value objects that are returned from service methods,
3
+ # instead of just returning a hash.
4
+ #
5
+ # Usage:
6
+ # class Foo < Percy::KeywordStruct.new(:bar, :baz, :qux)
7
+ # end
8
+ #
9
+ # foo = Foo.new(bar: 123, baz: true)
10
+ # foo.bar # --> 123
11
+ # foo.baz # --> true
12
+ # foo.qux # --> nil
13
+ # foo.fake # --> raises NoMethodError
14
+ module Percy
15
+ class KeywordStruct < Struct
16
+ def initialize(**kwargs)
17
+ super(kwargs.keys)
18
+ kwargs.each { |k, v| self[k] = v }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'timeout'
2
+
3
+ module Percy
4
+ class ProcessHelpers
5
+ DEFAULT_TERM_GRACE_SECONDS = 10
6
+
7
+ def self.gracefully_kill(pid, grace_period_seconds: DEFAULT_TERM_GRACE_SECONDS)
8
+ begin
9
+ Process.kill('TERM', pid)
10
+ Timeout.timeout(grace_period_seconds) do
11
+ Process.wait(pid)
12
+ end
13
+ rescue Errno::ESRCH
14
+ # No such process.
15
+ return false
16
+ rescue Errno::ECHILD
17
+ # Status has already been collected, perhaps by a Process.detach thread.
18
+ return false
19
+ rescue Timeout::Error
20
+ Process.kill('KILL', pid)
21
+ # Collect status so it doesn't stick around as zombie process.
22
+ Process.wait(pid, Process::WNOHANG)
23
+ end
24
+ true
25
+ end
26
+ end
27
+ end
@@ -20,7 +20,7 @@ module Percy
20
20
  end
21
21
 
22
22
  def stop_timing(stat, options = {})
23
- raise 'no timing started' if !@_timing_start # Programmer mistake, so raise an error.
23
+ raise 'no timing started' unless @_timing_start # Programmer mistake, so raise an error.
24
24
  time_since(stat, @_timing_start, options)
25
25
  @_timing_start = nil
26
26
  true
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency 'dogstatsd-ruby', '~> 1.6'
20
20
  spec.add_dependency 'syslog-logger', '~> 1.6'
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'bundler', '~> 1.15'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
  spec.add_development_dependency 'rspec', '~> 3.2'
25
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
26
+ spec.add_development_dependency 'percy-style'
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogstatsd-ruby
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.10'
47
+ version: '1.15'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.10'
54
+ version: '1.15'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: percy-style
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: ''
84
112
  email:
85
113
  - team@percy.io
@@ -89,14 +117,18 @@ extra_rdoc_files: []
89
117
  files:
90
118
  - ".gitignore"
91
119
  - ".rspec"
120
+ - ".rubocop.yml"
92
121
  - ".travis.yml"
93
122
  - Gemfile
123
+ - Guardfile
94
124
  - LICENSE
95
125
  - README.md
96
126
  - Rakefile
97
127
  - lib/percy/common.rb
98
128
  - lib/percy/common/version.rb
129
+ - lib/percy/keyword_struct.rb
99
130
  - lib/percy/logger.rb
131
+ - lib/percy/process_helpers.rb
100
132
  - lib/percy/stats.rb
101
133
  - percy-common.gemspec
102
134
  homepage: ''