execution_deadline 0.2.1 → 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/README.md +17 -0
- data/lib/execution_deadline/deadliner.rb +16 -3
- data/lib/execution_deadline/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ce574cf89fbb0b9cf89f8fc2df628aa171e89eef75b85f4e3ef5e3fcc5a8cd5
|
4
|
+
data.tar.gz: b1d29c6a81aae730323444e6a302262239d72df16652fd2a592a4f3ea99f1662
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a1ea9cc41b1c35c2f72e7cdd2e467b6e3adb9cce912e118f214f4bbf8592bbea623a711440566bcee4a786418476df19f6513473074f0d2f3b536f9a2c78211
|
7
|
+
data.tar.gz: 6bb2ccd7d1d27195ed3782074a2f42872777776e26c50d2423362741626740c27f42c5d9fe298b159166c18f542f95ba122385533cd45cf9401026e86f82986b
|
data/README.md
CHANGED
@@ -139,6 +139,23 @@ end
|
|
139
139
|
SlowModule.perform # Throws OutOfTime error
|
140
140
|
```
|
141
141
|
|
142
|
+
### Method interruption
|
143
|
+
Ruby's Timeout module is a bit heavy handed and could terminate operations at any point in your code flow. This gem
|
144
|
+
is an attempt at marking interruption points at the start and end of slow methods. It should always be preferred to
|
145
|
+
use a more graceful method, but sometimes a hammer is called for.
|
146
|
+
|
147
|
+
If you declare a deadline with `interruptible: true`. Ruby's Timeout module will be wrapped around your method set to
|
148
|
+
timeout at the remaining deadline time. The error will be replaced with the value of `raises` or the built in classes.
|
149
|
+
|
150
|
+
#### Example
|
151
|
+
```
|
152
|
+
deadline runs_for: 0.6, interruptible: true
|
153
|
+
def self.sub_method_1
|
154
|
+
sleep 0.7
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
|
142
159
|
### Raised Errors
|
143
160
|
`ExecutionDeadline::OutOfTime` - Raised when a deadlined method is called but
|
144
161
|
there is less time left then the expected runtime.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
module ExecutionDeadline
|
2
4
|
module Deadliner
|
3
5
|
WRAPPED_METHOD = Proc.new do |options|
|
@@ -7,10 +9,21 @@ module ExecutionDeadline
|
|
7
9
|
raises: options[:raises]
|
8
10
|
)
|
9
11
|
|
10
|
-
ExecutionDeadline.current_deadline
|
11
|
-
|
12
|
-
|
12
|
+
current_deadline = ExecutionDeadline.current_deadline
|
13
|
+
current_deadline&.require_seconds_left!(options[:runs_for]) if options[:runs_for]
|
14
|
+
|
15
|
+
result = if !options[:interruptible]
|
16
|
+
super(*args, **kwargs, &blk)
|
17
|
+
else
|
18
|
+
Timeout.timeout(current_deadline&.time_left) do
|
19
|
+
super(*args, **kwargs, &blk)
|
20
|
+
rescue => Timeout::Error
|
21
|
+
end
|
13
22
|
end
|
23
|
+
|
24
|
+
current_deadline&.check_deadline_expiration!
|
25
|
+
|
26
|
+
result
|
14
27
|
ensure
|
15
28
|
ExecutionDeadline.clear_deadline! if set_deadline
|
16
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execution_deadline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Malinconico
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
99
|
+
rubygems_version: 3.1.2
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Manage code deadlines without the hard termination of Timeout
|