monotonic_tick_count 0.2.0.rails.5
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.jenkins/Jenkinsfile +51 -0
- data/.jenkins/ruby_build_pod.yml +19 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +20 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/monotonic_tick_count.rb +70 -0
- data/lib/monotonic_tick_count/version.rb +5 -0
- data/monotonic_tick_count.gemspec +31 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d8e5ad9be33e236d673cf046950b0552dc653e3fe01ac6b64db11e2bf374b5c8
|
4
|
+
data.tar.gz: 489038b62cb1c55e4677ba83bd55e1f035490e7510b18f0ca380b04887a071ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25def2306d8d0fe545f24299cdc058a878e579b72d2148d60e7c3f5fa0b79c2ba82671728d56bc88abefbf656e5bd36ce98a8983155cbb80d17bfaa70d1d0e0a
|
7
|
+
data.tar.gz: 965c2904c654dddbac57013fc2fc6c40e08ddfe4379c6bede0a1bb6979c16a6217dafffe33ba4a80d705756b2bc080fb62727bb99173cfd67940cf1fff66ceae
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/groovy
|
2
|
+
@Library('jenkins-pipeline@v0.4.5')
|
3
|
+
import com.invoca.docker.*;
|
4
|
+
pipeline {
|
5
|
+
agent {
|
6
|
+
kubernetes {
|
7
|
+
defaultContainer "ruby"
|
8
|
+
yamlFile ".jenkins/ruby_build_pod.yml"
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
environment {
|
13
|
+
GITHUB_TOKEN = credentials('github_token')
|
14
|
+
BUNDLE_GEM__FURY__IO = credentials('gemfury_deploy_token')
|
15
|
+
}
|
16
|
+
|
17
|
+
stages {
|
18
|
+
stage('Setup') {
|
19
|
+
steps {
|
20
|
+
updateGitHubStatus('clean-build', 'pending', 'Unit tests.')
|
21
|
+
script {
|
22
|
+
sh 'bundle install'
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
stage('Unit Test') {
|
27
|
+
steps {
|
28
|
+
script {
|
29
|
+
sh 'bundle exec rspec --format RspecJunitFormatter --out spec/reports/rspec.xml'
|
30
|
+
}
|
31
|
+
}
|
32
|
+
post {
|
33
|
+
always { junit '*/reports/*.xml' }
|
34
|
+
success { updateGitHubStatus('clean-build', 'success', 'Unit tests.') }
|
35
|
+
failure { updateGitHubStatus('clean-build', 'failure', 'Unit tests.') }
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
void updateGitHubStatus(String context, String status, String description) {
|
42
|
+
gitHubStatus([
|
43
|
+
repoSlug: 'Invoca/monotonic_tick_count',
|
44
|
+
sha: env.GIT_COMMIT,
|
45
|
+
description: description,
|
46
|
+
context: context,
|
47
|
+
targetURL: env.BUILD_URL,
|
48
|
+
token: env.GITHUB_TOKEN,
|
49
|
+
status: status
|
50
|
+
])
|
51
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
apiVersion: v1
|
3
|
+
kind: Pod
|
4
|
+
metadata:
|
5
|
+
labels:
|
6
|
+
jenkins/monotonic-tick_count: 'true'
|
7
|
+
namespace: jenkins
|
8
|
+
name: monotonic-tick_count
|
9
|
+
spec:
|
10
|
+
containers:
|
11
|
+
- name: ruby
|
12
|
+
image: ruby:2.6.5
|
13
|
+
tty: true
|
14
|
+
resources:
|
15
|
+
requests:
|
16
|
+
memory: "100Mi"
|
17
|
+
command:
|
18
|
+
- cat
|
19
|
+
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# This rubocop config file inherits from our centralized style-guide repository.
|
2
|
+
# If you are looking to update the ruby style guide, be sure to both update the rubocop config
|
3
|
+
# as well as the README.md
|
4
|
+
# https://github.com/Invoca/style-guide/tree/master/ruby
|
5
|
+
inherit_from: https://raw.githubusercontent.com/Invoca/style-guide/master/ruby/.rubocop.yml
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in monotonic_tick_count.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'bundler', '~> 1.17'
|
10
|
+
gem 'pry'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rspec', '~> 3.7'
|
13
|
+
gem 'rspec_junit_formatter', '~> 0.4'
|
14
|
+
gem 'rspec-mocks'
|
15
|
+
gem 'rubocop', '0.54.0'
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Colin Kelley
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# MonotonicTickCount
|
2
|
+
|
3
|
+
Implements a PORO that can be used for monotonic timestamping. It wraps a count of fractional seconds (or ticks) that can be initialized to the system monotonic clock via the `.now` method or to any float you supply. It implements the comparable interface and arithmetic operators for calculating offsets and differences.
|
4
|
+
|
5
|
+
For an explanation as to why this is preferrable to using the wall clock for timing calculations, see [this blog post](https://www.softwariness.com/articles/monotonic-clocks-windows-and-posix/).
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
Comparing two monotonic timestamps
|
9
|
+
```
|
10
|
+
tick_count_a = MonotonicTickCount.now
|
11
|
+
tick_count_b = tick_count_a + 15.minutes
|
12
|
+
tick_count_a < tick_count_b => true
|
13
|
+
tick_count_b - tick_count_a => 900.0
|
14
|
+
```
|
15
|
+
|
16
|
+
Finding the elapsed seconds of a block
|
17
|
+
```
|
18
|
+
return_val, elapsed_seconds = MonotonicTickCount.timer do
|
19
|
+
sleep(10)
|
20
|
+
1
|
21
|
+
end
|
22
|
+
return_val => 1
|
23
|
+
elapsed_seconds => 10.0
|
24
|
+
```
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gem 'monotonic_tick_count'
|
32
|
+
```
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
|
36
|
+
$ bundle
|
37
|
+
|
38
|
+
Or install it yourself as:
|
39
|
+
|
40
|
+
$ gem install monotonic_tick_count
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
+
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/monotonic_tick_count.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "bundler/gem_tasks"
|
7
|
+
|
8
|
+
begin
|
9
|
+
Bundler.setup(:default, :development)
|
10
|
+
rescue Bundler::BundlerError => e
|
11
|
+
warn e.message
|
12
|
+
warn "Run `bundle install` to install missing gems"
|
13
|
+
exit e.status_code
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new do |t|
|
17
|
+
t.pattern = 'spec/**/*_spec.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
task default: :spec
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "monotonic_tick_count"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "monotonic_tick_count/version"
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/core_ext"
|
6
|
+
|
7
|
+
class MonotonicTickCount
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
# the tick count in seconds as floating point at nanosecond granularity
|
11
|
+
attr_reader :tick_count_f
|
12
|
+
|
13
|
+
# initialize from one of:
|
14
|
+
# - another object of this type OR
|
15
|
+
# - an equivalent object that responds to tick_count_f OR
|
16
|
+
# - an explicit keyword value of tick_count_f: which is a floating point count of seconds with fractional second at nanosecond granularity
|
17
|
+
def initialize(other = nil, tick_count_f: nil)
|
18
|
+
@tick_count_f = if other
|
19
|
+
other.respond_to?(:tick_count_f) or raise ArgumentError, "Must initialize from #{self.class} or equivalent"
|
20
|
+
other.tick_count_f
|
21
|
+
else
|
22
|
+
tick_count_f or raise ArgumentError, "Must provide either other or tick_count_f:"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
"monotonic tick count #{@tick_count_f}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# When the RHS is a convertible to float, returns an offset to the current tick count
|
31
|
+
# When the RHS is a MonotonicTickCount, returns the difference in float seconds
|
32
|
+
def -(other)
|
33
|
+
if other.respond_to?(:tick_count_f)
|
34
|
+
@tick_count_f - other.tick_count_f
|
35
|
+
elsif other.respond_to?(:to_f)
|
36
|
+
self + -other
|
37
|
+
else
|
38
|
+
raise ArgumentError, "Other operand must be another #{self.class} or respond to to_f"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def +(other)
|
43
|
+
other.respond_to?(:to_f) or raise ArgumentError, "Other operand must respond to to_f"
|
44
|
+
self.class.new(tick_count_f: @tick_count_f + other.to_f)
|
45
|
+
end
|
46
|
+
|
47
|
+
def <=>(other)
|
48
|
+
other.respond_to?(:tick_count_f) or raise ArgumentError, "Other operand must be a #{self.class} or equivalent"
|
49
|
+
@tick_count_f <=> other.tick_count_f
|
50
|
+
end
|
51
|
+
|
52
|
+
def hash
|
53
|
+
@tick_count_f.hash
|
54
|
+
end
|
55
|
+
|
56
|
+
alias eql? ==
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def now
|
60
|
+
new(tick_count_f: Process.clock_gettime(Process::CLOCK_MONOTONIC))
|
61
|
+
end
|
62
|
+
|
63
|
+
# yields to the caller and returns a pair: [result from yield, float time in seconds of block run]
|
64
|
+
def timer
|
65
|
+
start = self.now
|
66
|
+
result = yield
|
67
|
+
[result, self.now - start]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require "monotonic_tick_count/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "monotonic_tick_count"
|
10
|
+
spec.version = MonotonicTickCount::VERSION
|
11
|
+
spec.authors = ["Invoca Development"]
|
12
|
+
spec.email = ["development@invoca.com"]
|
13
|
+
|
14
|
+
spec.summary = "PORO to hold a monotonic tick count. Useful for measuring time differences."
|
15
|
+
spec.description = spec.summary
|
16
|
+
spec.homepage = "https://github.com/invoca/monotonic_tick_count"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.metadata = {
|
20
|
+
"allowed_push_host" => "https://rubygems.org"
|
21
|
+
}
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "activesupport", ">= 4.2"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monotonic_tick_count
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0.rails.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Invoca Development
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: PORO to hold a monotonic tick count. Useful for measuring time differences.
|
28
|
+
email:
|
29
|
+
- development@invoca.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".jenkins/Jenkinsfile"
|
36
|
+
- ".jenkins/ruby_build_pod.yml"
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- ".travis.yml"
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- lib/monotonic_tick_count.rb
|
46
|
+
- lib/monotonic_tick_count/version.rb
|
47
|
+
- monotonic_tick_count.gemspec
|
48
|
+
homepage: https://github.com/invoca/monotonic_tick_count
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
allowed_push_host: https://rubygems.org
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.3.1
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.0.3
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: PORO to hold a monotonic tick count. Useful for measuring time differences.
|
72
|
+
test_files: []
|