resque-heroku-signals 1.27.4.2 → 1.27.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +10 -2
- data/lib/resque-heroku-signals.rb +10 -1
- data/resque-heroku-signals.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9c16646fceadc63c6de9f13561c375add6161ec
|
4
|
+
data.tar.gz: 852b25d7b002bc6c4c93caaa2ee587a9b5b53625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f966ab995b091384bf764b7305bc8459502bdcb03307878277e92b8f46afb88d84baaf029fa432432d29fbbcdeb95d8f0334c4a75d1554fa9f5a8bf1d477624e
|
7
|
+
data.tar.gz: 2949155a0ad39b5463b933429dafc039cb6efe4ac6e113db7cf498223aadcc0d29acb71fd15c137e69cb7b86aadc1334ac8589c06f70106e3af25f139b876069
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -15,7 +15,15 @@ Add this line to your application's Gemfile:
|
|
15
15
|
gem 'resque-heroku-signals'
|
16
16
|
```
|
17
17
|
|
18
|
-
Since this gem monkeypatches the Heroku worker the `gemspec` is locked to a `x.x.x` version of Resque. Issue a PR if this is not compatible with the version of resque you are using.
|
18
|
+
Since this gem monkeypatches the Heroku worker the `gemspec` is locked to a `x.x.x` version of Resque. Issue a PR if this is not compatible with the version of resque you are using.
|
19
|
+
|
20
|
+
## Determining When a Process Will Shutdown
|
21
|
+
|
22
|
+
Heroku sends a `TERM` signal to a process before hard killing it. If your job communicates with slow external APIs, you may want to make sure you have enough time to receive and handle the response from the external system before executing the API requests.
|
23
|
+
|
24
|
+
Ideally, using an idempotency key with each external API request is the best way to ensure that a given API request only runs. However, depending on your application logic this may not be practical and knowing if a process will be terminated in less than 30s by Heroku is a useful tool.
|
25
|
+
|
26
|
+
Use `Resque.heroku_will_terminate?` to determine if Heroku will terminate your process within 30s.
|
19
27
|
|
20
28
|
## Example Procfile
|
21
29
|
|
@@ -28,7 +36,7 @@ worker: env QUEUE=* TERM_CHILD=1 INTERVAL=0.1 RESQUE_PRE_SHUTDOWN_TIMEOUT=20 RES
|
|
28
36
|
* Total shutdown time should be less than 30s. This is the time [Heroku gives you to cleanup before a `SIGKILL` is issued](https://devcenter.heroku.com/articles/dynos#shutdown)
|
29
37
|
* `INTERVAL` seconds to wait between jobs
|
30
38
|
|
31
|
-
Also, make you don't buffer logs:
|
39
|
+
Also, make you don't buffer logs: important log messages could fail to push to stdout during the worker shutdown process:
|
32
40
|
|
33
41
|
```ruby
|
34
42
|
$stdout.sync = true
|
@@ -1,9 +1,19 @@
|
|
1
1
|
require 'resque'
|
2
2
|
|
3
|
+
$HEROKU_WILL_TERMINATE_RESQUE = false
|
4
|
+
|
5
|
+
Resque.class_eval do
|
6
|
+
def self.heroku_will_terminate?
|
7
|
+
!!$HEROKU_WILL_TERMINATE_RESQUE
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
# https://github.com/resque/resque/issues/1559#issuecomment-310908574
|
4
12
|
Resque::Worker.class_eval do
|
5
13
|
def unregister_signal_handlers
|
6
14
|
trap('TERM') do
|
15
|
+
$HEROKU_WILL_TERMINATE_RESQUE = true
|
16
|
+
|
7
17
|
trap('TERM') do
|
8
18
|
log_with_severity :info, "[resque-heroku] received second term signal, throwing term exception"
|
9
19
|
|
@@ -15,7 +25,6 @@ Resque::Worker.class_eval do
|
|
15
25
|
end
|
16
26
|
|
17
27
|
log_with_severity :info, "[resque-heroku] received first term signal from heroku, ignoring"
|
18
|
-
|
19
28
|
end
|
20
29
|
|
21
30
|
trap('INT', 'DEFAULT')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-heroku-signals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.27.4.
|
4
|
+
version: 1.27.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bianco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|