cutoff 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +16 -0
- data/lib/cutoff.rb +28 -25
- data/lib/cutoff/timer.rb +32 -0
- data/lib/cutoff/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8010fa3d0714c498fdb4ec4d34ea2dbf9fe4b05f534521d029adf370a51300bc
|
4
|
+
data.tar.gz: 1ba8ed1d6b3c544ab72bc549be87b70c0e9b23c0594bcf74319e828abe0834a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6ada9ba95a71a0717e79f1e0ab113910b4693ad285452dd0852a36d7f6613f57878d9272ae9d088334e2571c3b06a68d01dc0a2d8d92b1d835aec33858def8
|
7
|
+
data.tar.gz: 14021607c75f24f0a8bbbeb711adb42f2d93c526ea30ba76386b972b108818fcb05a23bc4b4035659a76791fdeff4cf821478e95d0e4107af65ffe03a38f1f5d
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2021-08-20
|
11
|
+
|
12
|
+
- Allow timers to be disabled globally with `Cutoff.disable!`
|
13
|
+
|
10
14
|
## [0.2.0] - 2021-07-22
|
11
15
|
|
12
16
|
### Added
|
@@ -20,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
20
24
|
- Cutoff class
|
21
25
|
- Mysql2 patch
|
22
26
|
|
23
|
-
[Unreleased]: https://github.com/justinhoward/cutoff/compare/v0.
|
27
|
+
[Unreleased]: https://github.com/justinhoward/cutoff/compare/v0.3.0...HEAD
|
28
|
+
[0.3.0]: https://github.com/justinhoward/cutoff/compare/v0.2.0...v0.3.0
|
24
29
|
[0.2.0]: https://github.com/justinhoward/cutoff/compare/v0.1.0...v0.2.0
|
25
30
|
[0.1.0]: https://github.com/justinhoward/cutoff/releases/tag/v0.1.0
|
data/README.md
CHANGED
@@ -250,6 +250,22 @@ class ApplicationController < ActionController::Base
|
|
250
250
|
end
|
251
251
|
```
|
252
252
|
|
253
|
+
Disabling Cutoff for Testing and Development
|
254
|
+
------------
|
255
|
+
|
256
|
+
When testing or debugging an application that uses Cutoff, you may want to
|
257
|
+
disable Cutoff entirely. These methods are not thread-safe and not intended for
|
258
|
+
production.
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
# This disables all cutoff timers, for both global and local instances
|
262
|
+
Cutoff.disable!
|
263
|
+
Cutoff.disabled? # => true
|
264
|
+
|
265
|
+
# Re-enable cutoff
|
266
|
+
Cutoff.enable!
|
267
|
+
```
|
268
|
+
|
253
269
|
Multi-threading
|
254
270
|
-----------------
|
255
271
|
|
data/lib/cutoff.rb
CHANGED
@@ -3,11 +3,14 @@
|
|
3
3
|
require_relative 'cutoff/version'
|
4
4
|
require_relative 'cutoff/error'
|
5
5
|
require_relative 'cutoff/patch'
|
6
|
+
require_relative 'cutoff/timer'
|
6
7
|
|
7
8
|
class Cutoff
|
8
9
|
CURRENT_STACK_KEY = 'cutoff_deadline_stack'
|
9
10
|
private_constant :CURRENT_STACK_KEY
|
10
11
|
|
12
|
+
extend Timer
|
13
|
+
|
11
14
|
class << self
|
12
15
|
# Get the current {Cutoff} if one is set
|
13
16
|
def current
|
@@ -85,31 +88,29 @@ class Cutoff
|
|
85
88
|
cutoff.checkpoint!
|
86
89
|
end
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
Time.now.to_f
|
112
|
-
end
|
91
|
+
# Disable Cutoff globally. Useful for testing and debugging
|
92
|
+
#
|
93
|
+
# Should not be used in production
|
94
|
+
#
|
95
|
+
# @return [void]
|
96
|
+
def disable!
|
97
|
+
@disabled = true
|
98
|
+
end
|
99
|
+
|
100
|
+
# Enable Cutoff globally if it has been disabled
|
101
|
+
#
|
102
|
+
# Should not be used in production
|
103
|
+
#
|
104
|
+
# @return [void]
|
105
|
+
def enable!
|
106
|
+
@disabled = false
|
107
|
+
end
|
108
|
+
|
109
|
+
# True if cutoff was disabled with {#disable!}
|
110
|
+
#
|
111
|
+
# @return [Boolean] True if disabled
|
112
|
+
def disabled?
|
113
|
+
@disabled == true
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
@@ -144,6 +145,8 @@ class Cutoff
|
|
144
145
|
#
|
145
146
|
# @return [Float] The number of seconds
|
146
147
|
def elapsed_seconds
|
148
|
+
return 0 if Cutoff.disabled?
|
149
|
+
|
147
150
|
Cutoff.now - @start_time
|
148
151
|
end
|
149
152
|
|
data/lib/cutoff/timer.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal:true
|
2
|
+
|
3
|
+
class Cutoff
|
4
|
+
module Timer
|
5
|
+
if defined?(Process::CLOCK_MONOTONIC_RAW)
|
6
|
+
# The current time
|
7
|
+
#
|
8
|
+
# If it is available, this will use a monotonic clock. This is a clock
|
9
|
+
# that always moves forward in time. If that is not available on this
|
10
|
+
# system, `Time.now` will be used
|
11
|
+
#
|
12
|
+
# @return [Float] The current time as a float
|
13
|
+
def now
|
14
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC_RAW)
|
15
|
+
end
|
16
|
+
elsif defined?(Process::CLOCK_MONOTONIC)
|
17
|
+
def now
|
18
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
19
|
+
end
|
20
|
+
elsif Gem.loaded_specs['concurrent-ruby']
|
21
|
+
require 'concurrent-ruby'
|
22
|
+
|
23
|
+
def now
|
24
|
+
Concurrent.monotonic_time
|
25
|
+
end
|
26
|
+
else
|
27
|
+
def now
|
28
|
+
Time.now.to_f
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cutoff/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cutoff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -88,13 +88,14 @@ files:
|
|
88
88
|
- lib/cutoff/patch.rb
|
89
89
|
- lib/cutoff/patch/mysql2.rb
|
90
90
|
- lib/cutoff/patch/net_http.rb
|
91
|
+
- lib/cutoff/timer.rb
|
91
92
|
- lib/cutoff/version.rb
|
92
93
|
homepage: https://github.com/justinhoward/cutoff
|
93
94
|
licenses:
|
94
95
|
- MIT
|
95
96
|
metadata:
|
96
97
|
changelog_uri: https://github.com/justinhoward/cutoff/blob/master/CHANGELOG.md
|
97
|
-
documentation_uri: https://www.rubydoc.info/gems/cutoff/0.
|
98
|
+
documentation_uri: https://www.rubydoc.info/gems/cutoff/0.3.0
|
98
99
|
post_install_message:
|
99
100
|
rdoc_options: []
|
100
101
|
require_paths:
|