Skip to content

Commit 405c557

Browse files
author
Doug Edey
committed
Switch to redis-ttl and use CI_QUEUE_REDIS_TTL as an env to set defaults
1 parent 1dc4b25 commit 405c557

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Two implementations are provided, please refer to the respective documentations:
4040
## Redis Requirements
4141

4242
`ci-queue` expects the Redis server to have an [eviction policy](https://redis.io/docs/manual/eviction/#eviction-policies) of `allkeys-lru`.
43+
4344
## Contributing
4445

4546
Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/ci-queue.

ruby/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ Because of how `ci-queue` executes the examples, `before(:all)` and `after(:all)
7575

7676
`ci-queue` expects the Redis server to have an [eviction policy](https://redis.io/docs/manual/eviction/#eviction-policies) of `allkeys-lru`.
7777

78-
You can also use `--report-expires-in` to set a custom expiration time for all CI Queue keys, this defaults to 8 hours (28,800 seconds)
78+
You can also use `--redis-ttl` to set a custom expiration time for all CI Queue keys, this defaults to 8 hours (28,800 seconds)

ruby/lib/ci/queue/configuration.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Configuration
55
attr_accessor :timeout, :worker_id, :max_requeues, :grind_count, :failure_file
66
attr_accessor :requeue_tolerance, :namespace, :failing_test, :statsd_endpoint
77
attr_accessor :max_test_duration, :max_test_duration_percentile, :track_test_duration
8-
attr_accessor :max_test_failed, :report_expires_in
8+
attr_accessor :max_test_failed, :redis_ttl
99
attr_reader :circuit_breakers
1010
attr_writer :seed, :build_id
1111
attr_writer :queue_init_timeout
@@ -18,6 +18,7 @@ def from_env(env)
1818
seed: env['CIRCLE_SHA1'] || env['BUILDKITE_COMMIT'] || env['TRAVIS_COMMIT'] || env['HEROKU_TEST_RUN_COMMIT_VERSION'] || env['SEMAPHORE_GIT_SHA'],
1919
flaky_tests: load_flaky_tests(env['CI_QUEUE_FLAKY_TESTS']),
2020
statsd_endpoint: env['CI_QUEUE_STATSD_ADDR'],
21+
redis_ttl: env['CI_QUEUE_REDIS_TTL'],
2122
)
2223
end
2324

@@ -34,7 +35,7 @@ def initialize(
3435
namespace: nil, seed: nil, flaky_tests: [], statsd_endpoint: nil, max_consecutive_failures: nil,
3536
grind_count: nil, max_duration: nil, failure_file: nil, max_test_duration: nil,
3637
max_test_duration_percentile: 0.5, track_test_duration: false, max_test_failed: nil,
37-
queue_init_timeout: nil, report_expires_in: 8 * 60 * 60
38+
queue_init_timeout: nil, redis_ttl: 8 * 60 * 60
3839
)
3940
@build_id = build_id
4041
@circuit_breakers = [CircuitBreaker::Disabled]
@@ -55,7 +56,7 @@ def initialize(
5556
@worker_id = worker_id
5657
self.max_consecutive_failures = max_consecutive_failures
5758
self.max_duration = max_duration
58-
@report_expires_in = report_expires_in
59+
@redis_ttl = redis_ttl
5960
end
6061

6162
def queue_init_timeout

ruby/lib/ci/queue/redis/build_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def record_error(id, payload, stats: nil)
4141
id.dup.force_encoding(Encoding::BINARY),
4242
payload.dup.force_encoding(Encoding::BINARY),
4343
)
44-
pipeline.expire(key('error-reports'), config.report_expires_in)
44+
pipeline.expire(key('error-reports'), config.redis_ttl)
4545
record_stats(stats, pipeline: pipeline)
4646
end
4747
nil
@@ -91,7 +91,7 @@ def record_stats(stats, pipeline: redis)
9191
return unless stats
9292
stats.each do |stat_name, stat_value|
9393
pipeline.hset(key(stat_name), config.worker_id, stat_value)
94-
pipeline.expire(key(stat-name), config.report_expires_in)
94+
pipeline.expire(key(stat-name), config.redis_ttl)
9595
end
9696
end
9797

ruby/lib/ci/queue/redis/grind_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def record_error(payload, stats: nil)
1616
key('error-reports'),
1717
payload.force_encoding(Encoding::BINARY),
1818
)
19-
pipeline.expire(key('error-reports'), config.report_expires_in)
19+
pipeline.expire(key('error-reports'), config.redis_ttl)
2020
record_stats(stats, pipeline: pipeline)
2121
end
2222
nil
@@ -59,7 +59,7 @@ def record_stats(stats, pipeline: redis)
5959
return unless stats
6060
stats.each do |stat_name, stat_value|
6161
pipeline.hset(key(stat_name), config.worker_id, stat_value)
62-
pipeline.expire(key(stat_name), config.report_expires_in)
62+
pipeline.expire(key(stat_name), config.redis_ttl)
6363
end
6464
end
6565
end

ruby/lib/ci/queue/redis/test_time_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def record_test_time(test_name, duration)
2424
test_time_key(test_name),
2525
duration.to_s.force_encoding(Encoding::BINARY),
2626
)
27-
pipeline.expire(test_time_key(test_name), config.report_expires_in)
27+
pipeline.expire(test_time_key(test_name), config.redis_ttl)
2828
end
2929
nil
3030
end
@@ -35,7 +35,7 @@ def record_test_name(test_name)
3535
all_test_names_key,
3636
test_name.dup.force_encoding(Encoding::BINARY),
3737
)
38-
pipeline.expire(all_test_names_key, config.report_expires_in)
38+
pipeline.expire(all_test_names_key, config.redis_ttl)
3939
end
4040
nil
4141
end

ruby/lib/ci/queue/redis/worker.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def poll
5454
end
5555
end
5656
redis.pipelined do |pipeline|
57-
pipeline.expire(key('worker', worker_id, 'queue'), config.report_expires_in)
58-
pipeline.expire(key('processed'), config.report_expires_in)
57+
pipeline.expire(key('worker', worker_id, 'queue'), config.redis_ttl)
58+
pipeline.expire(key('processed'), config.redis_ttl)
5959
end
6060
rescue *CONNECTION_ERRORS
6161
end
@@ -203,13 +203,13 @@ def push(tests)
203203
transaction.set(key('total'), @total)
204204
transaction.set(key('master-status'), 'ready')
205205

206-
transaction.expire(key('queue'), config.report_expires_in)
207-
transaction.expire(key('total'), config.report_expires_in)
208-
transaction.expire(key('master-status'), config.report_expires_in)
206+
transaction.expire(key('queue'), config.redis_ttl)
207+
transaction.expire(key('total'), config.redis_ttl)
208+
transaction.expire(key('master-status'), config.redis_ttl)
209209
end
210210
end
211211
register
212-
redis.expire(key('workers'), config.report_expires_in)
212+
redis.expire(key('workers'), config.redis_ttl)
213213
rescue *CONNECTION_ERRORS
214214
raise if @master
215215
end

ruby/lib/minitest/queue/runner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ def parser
491491
Defines how long the test report remain after the test run, in seconds.
492492
Defaults to 28,800 (8 hours)
493493
EOS
494-
opts.on("--report-expires-in SECONDS", Integer, help) do |time|
495-
queue.config.report_expires_in = time
494+
opts.on("--redis-ttl SECONDS", Integer, help) do |time|
495+
queue.config.redis_ttl = time
496496
end
497497

498498
opts.separator ""

ruby/lib/rspec/queue.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def parser(options)
162162
Defaults to 28,800 (8 hours)
163163
EOS
164164
parsed.separator ""
165-
parser.on("--report-expires-in SECONDS", Integer, help) do |time|
166-
queue.config.report_expires_in = time
165+
parser.on("--redis-ttl SECONDS", Integer, help) do |time|
166+
queue.config.redis_ttl = time
167167
end
168168

169169
parser

0 commit comments

Comments
 (0)