Skip to content

Commit becb899

Browse files
authored
Merge pull request #1470 from Shopify/configurable-presence-check-timeout
Make PRESENCE_CHECK_TIMEOUT configurable via env var
2 parents 581d6f6 + 52a05e3 commit becb899

File tree

7 files changed

+113
-62
lines changed

7 files changed

+113
-62
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
# 0.45.1
4+
* Make `PRESENCE_CHECK_TIMEOUT` configurable via environment variable
5+
36
# 0.45.0
47
* Shipit-engine now requires application to be at least on Rails 8.1.1.
58
* Remove dependency on SaasC that is lo longer maintained. A vanilla CSS file now ships with shipit-engine.

Gemfile.lock

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
shipit-engine (0.45.0)
4+
shipit-engine (0.45.1)
55
active_model_serializers (~> 0.9.3)
66
ansi_stream (~> 0.0.6)
77
autoprefixer-rails (~> 6.4.1)
@@ -32,71 +32,71 @@ PATH
3232
GEM
3333
remote: https://rubygems.org/
3434
specs:
35-
action_text-trix (2.1.15)
35+
action_text-trix (2.1.17)
3636
railties
37-
actioncable (8.1.1)
38-
actionpack (= 8.1.1)
39-
activesupport (= 8.1.1)
37+
actioncable (8.1.2)
38+
actionpack (= 8.1.2)
39+
activesupport (= 8.1.2)
4040
nio4r (~> 2.0)
4141
websocket-driver (>= 0.6.1)
4242
zeitwerk (~> 2.6)
43-
actionmailbox (8.1.1)
44-
actionpack (= 8.1.1)
45-
activejob (= 8.1.1)
46-
activerecord (= 8.1.1)
47-
activestorage (= 8.1.1)
48-
activesupport (= 8.1.1)
43+
actionmailbox (8.1.2)
44+
actionpack (= 8.1.2)
45+
activejob (= 8.1.2)
46+
activerecord (= 8.1.2)
47+
activestorage (= 8.1.2)
48+
activesupport (= 8.1.2)
4949
mail (>= 2.8.0)
50-
actionmailer (8.1.1)
51-
actionpack (= 8.1.1)
52-
actionview (= 8.1.1)
53-
activejob (= 8.1.1)
54-
activesupport (= 8.1.1)
50+
actionmailer (8.1.2)
51+
actionpack (= 8.1.2)
52+
actionview (= 8.1.2)
53+
activejob (= 8.1.2)
54+
activesupport (= 8.1.2)
5555
mail (>= 2.8.0)
5656
rails-dom-testing (~> 2.2)
57-
actionpack (8.1.1)
58-
actionview (= 8.1.1)
59-
activesupport (= 8.1.1)
57+
actionpack (8.1.2)
58+
actionview (= 8.1.2)
59+
activesupport (= 8.1.2)
6060
nokogiri (>= 1.8.5)
6161
rack (>= 2.2.4)
6262
rack-session (>= 1.0.1)
6363
rack-test (>= 0.6.3)
6464
rails-dom-testing (~> 2.2)
6565
rails-html-sanitizer (~> 1.6)
6666
useragent (~> 0.16)
67-
actiontext (8.1.1)
67+
actiontext (8.1.2)
6868
action_text-trix (~> 2.1.15)
69-
actionpack (= 8.1.1)
70-
activerecord (= 8.1.1)
71-
activestorage (= 8.1.1)
72-
activesupport (= 8.1.1)
69+
actionpack (= 8.1.2)
70+
activerecord (= 8.1.2)
71+
activestorage (= 8.1.2)
72+
activesupport (= 8.1.2)
7373
globalid (>= 0.6.0)
7474
nokogiri (>= 1.8.5)
75-
actionview (8.1.1)
76-
activesupport (= 8.1.1)
75+
actionview (8.1.2)
76+
activesupport (= 8.1.2)
7777
builder (~> 3.1)
7878
erubi (~> 1.11)
7979
rails-dom-testing (~> 2.2)
8080
rails-html-sanitizer (~> 1.6)
8181
active_model_serializers (0.9.13)
8282
activemodel (>= 3.2)
8383
concurrent-ruby (~> 1.0)
84-
activejob (8.1.1)
85-
activesupport (= 8.1.1)
84+
activejob (8.1.2)
85+
activesupport (= 8.1.2)
8686
globalid (>= 0.3.6)
87-
activemodel (8.1.1)
88-
activesupport (= 8.1.1)
89-
activerecord (8.1.1)
90-
activemodel (= 8.1.1)
91-
activesupport (= 8.1.1)
87+
activemodel (8.1.2)
88+
activesupport (= 8.1.2)
89+
activerecord (8.1.2)
90+
activemodel (= 8.1.2)
91+
activesupport (= 8.1.2)
9292
timeout (>= 0.4.0)
93-
activestorage (8.1.1)
94-
actionpack (= 8.1.1)
95-
activejob (= 8.1.1)
96-
activerecord (= 8.1.1)
97-
activesupport (= 8.1.1)
93+
activestorage (8.1.2)
94+
actionpack (= 8.1.2)
95+
activejob (= 8.1.2)
96+
activerecord (= 8.1.2)
97+
activesupport (= 8.1.2)
9898
marcel (~> 1.0)
99-
activesupport (8.1.1)
99+
activesupport (8.1.2)
100100
base64
101101
bigdecimal
102102
concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -262,8 +262,7 @@ GEM
262262
parser (3.3.8.0)
263263
ast (~> 2.4.1)
264264
racc
265-
pg (1.6.3-arm64-darwin)
266-
pg (1.6.3-x86_64-linux)
265+
pg (1.3.3)
267266
prism (1.4.0)
268267
pry (0.14.1)
269268
coderay (~> 1.1)
@@ -276,28 +275,28 @@ GEM
276275
rack
277276
redis (~> 4.0)
278277
racc (1.8.1)
279-
rack (2.2.22)
278+
rack (2.2.17)
280279
rack-session (1.0.2)
281280
rack (< 3)
282281
rack-test (2.2.0)
283282
rack (>= 1.3)
284283
rackup (1.0.0)
285284
rack (< 3)
286285
webrick
287-
rails (8.1.1)
288-
actioncable (= 8.1.1)
289-
actionmailbox (= 8.1.1)
290-
actionmailer (= 8.1.1)
291-
actionpack (= 8.1.1)
292-
actiontext (= 8.1.1)
293-
actionview (= 8.1.1)
294-
activejob (= 8.1.1)
295-
activemodel (= 8.1.1)
296-
activerecord (= 8.1.1)
297-
activestorage (= 8.1.1)
298-
activesupport (= 8.1.1)
286+
rails (8.1.2)
287+
actioncable (= 8.1.2)
288+
actionmailbox (= 8.1.2)
289+
actionmailer (= 8.1.2)
290+
actionpack (= 8.1.2)
291+
actiontext (= 8.1.2)
292+
actionview (= 8.1.2)
293+
activejob (= 8.1.2)
294+
activemodel (= 8.1.2)
295+
activerecord (= 8.1.2)
296+
activestorage (= 8.1.2)
297+
activesupport (= 8.1.2)
299298
bundler (>= 1.15.0)
300-
railties (= 8.1.1)
299+
railties (= 8.1.2)
301300
rails-dom-testing (2.3.0)
302301
activesupport (>= 5.0.0)
303302
minitest
@@ -312,9 +311,9 @@ GEM
312311
actionview (> 3.1)
313312
activesupport (> 3.1)
314313
railties (> 3.1)
315-
railties (8.1.1)
316-
actionpack (= 8.1.1)
317-
activesupport (= 8.1.1)
314+
railties (8.1.2)
315+
actionpack (= 8.1.2)
316+
activesupport (= 8.1.2)
318317
irb (~> 1.13)
319318
rackup (>= 1.0.0)
320319
rake (>= 12.2)

app/models/shipit/task.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def message
1010
end
1111
end
1212

13-
PRESENCE_CHECK_TIMEOUT = 30
1413
ACTIVE_STATUSES = %w[pending running aborting].freeze
1514
COMPLETED_STATUSES = %w[success flapping faulty validating].freeze
1615
UNSUCCESSFUL_STATUSES = %w[error failed aborted flapping timedout faulty].freeze
@@ -327,15 +326,15 @@ def finished?
327326
end
328327

329328
def ping
330-
Shipit.redis.set(status_key, 'alive', ex: PRESENCE_CHECK_TIMEOUT)
329+
Shipit.redis.set(status_key, 'alive', ex: Shipit.presence_check_timeout)
331330
end
332331

333332
def alive?
334333
Shipit.redis.get(status_key) == 'alive'
335334
end
336335

337336
def report_dead!
338-
write("ERROR: Background job hasn't reported back in #{PRESENCE_CHECK_TIMEOUT} seconds.")
337+
write("ERROR: Background job hasn't reported back in #{Shipit.presence_check_timeout} seconds.")
339338
error!
340339
end
341340

docs/setup.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ production:
171171
git_progress_output: true
172172
```
173173

174+
### Environment Variables
175+
176+
**`SHIPIT_PRESENCE_CHECK_TIMEOUT`** is the duration (in seconds) after which a deploy task is considered dead if the background job hasn't reported back. Defaults to `30`. Increase this if deploy tasks are being reaped during long-running steps like `bundle install` with native extension compilation.
177+
178+
```bash
179+
export SHIPIT_PRESENCE_CHECK_TIMEOUT=120
180+
```
181+
174182
### Using Multiple Github Applications
175183

176184
A Github application can only authenticate to the Github organization it's installed in. If you want to deploy code from multiple Github organizations the `github` section of your `config/secrets.yml` will need to be formatted differently. The top-level keys should be the name of each Github organization, and the following sub-keys are the Github app details for that particular organization.

lib/shipit.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def enable_samesite_middleware?
9191
ENV['SHIPIT_ENABLE_SAMESITE_NONE'].present?
9292
end
9393

94+
def presence_check_timeout
95+
raw = ENV.fetch('SHIPIT_PRESENCE_CHECK_TIMEOUT', '30')
96+
timeout = Integer(raw)
97+
raise ArgumentError, "SHIPIT_PRESENCE_CHECK_TIMEOUT must be a positive integer, got #{raw.inspect}" if timeout <= 0
98+
99+
timeout
100+
end
101+
94102
def app_name
95103
@app_name ||= secrets.app_name || Rails.application.class.name.split(':').first || 'Shipit'
96104
end

lib/shipit/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Shipit
4-
VERSION = '0.45.0'
4+
VERSION = '0.45.1'
55
end

test/unit/shipit_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,40 @@ class ShipitTest < ActiveSupport::TestCase
3030
assert_equal(['shopify/developers'], Shipit.github_teams.map(&:handle))
3131
end
3232

33+
test ".presence_check_timeout defaults to 30" do
34+
assert_equal 30, Shipit.presence_check_timeout
35+
end
36+
37+
test ".presence_check_timeout returns the configured value from ENV" do
38+
ENV['SHIPIT_PRESENCE_CHECK_TIMEOUT'] = '120'
39+
assert_equal 120, Shipit.presence_check_timeout
40+
ensure
41+
ENV.delete('SHIPIT_PRESENCE_CHECK_TIMEOUT')
42+
end
43+
44+
test ".presence_check_timeout raises on non-numeric string" do
45+
ENV['SHIPIT_PRESENCE_CHECK_TIMEOUT'] = 'abc'
46+
assert_raises(ArgumentError) { Shipit.presence_check_timeout }
47+
ensure
48+
ENV.delete('SHIPIT_PRESENCE_CHECK_TIMEOUT')
49+
end
50+
51+
test ".presence_check_timeout raises on zero" do
52+
ENV['SHIPIT_PRESENCE_CHECK_TIMEOUT'] = '0'
53+
error = assert_raises(ArgumentError) { Shipit.presence_check_timeout }
54+
assert_match(/must be a positive integer/, error.message)
55+
ensure
56+
ENV.delete('SHIPIT_PRESENCE_CHECK_TIMEOUT')
57+
end
58+
59+
test ".presence_check_timeout raises on negative value" do
60+
ENV['SHIPIT_PRESENCE_CHECK_TIMEOUT'] = '-5'
61+
error = assert_raises(ArgumentError) { Shipit.presence_check_timeout }
62+
assert_match(/must be a positive integer/, error.message)
63+
ensure
64+
ENV.delete('SHIPIT_PRESENCE_CHECK_TIMEOUT')
65+
end
66+
3367
class RedisTest < self
3468
setup do
3569
@client = mock(:client)

0 commit comments

Comments
 (0)