diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-25 09:08:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-25 09:08:11 +0000 |
commit | 5064bf8c5647d4c4430cbb4d097cf1592416de29 (patch) | |
tree | d051bf2abe2cc7061b3a7facb6669a56ccb9cf54 /lib/gitlab/sidekiq_cluster/cli.rb | |
parent | 9c83aadd2604e7e6cb1f84683f951e6b12872618 (diff) | |
download | gitlab-ce-5064bf8c5647d4c4430cbb4d097cf1592416de29.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/sidekiq_cluster/cli.rb')
-rw-r--r-- | lib/gitlab/sidekiq_cluster/cli.rb | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/gitlab/sidekiq_cluster/cli.rb b/lib/gitlab/sidekiq_cluster/cli.rb index 245d918e382..f1befe4aff1 100644 --- a/lib/gitlab/sidekiq_cluster/cli.rb +++ b/lib/gitlab/sidekiq_cluster/cli.rb @@ -8,9 +8,17 @@ module Gitlab module SidekiqCluster class CLI CHECK_TERMINATE_INTERVAL_SECONDS = 1 - # How long to wait in total when asking for a clean termination - # Sidekiq default to self-terminate is 25s - TERMINATE_TIMEOUT_SECONDS = 30 + + # How long to wait when asking for a clean termination. + # It maps the Sidekiq default timeout: + # https://github.com/mperham/sidekiq/wiki/Signals#term + # + # This value is passed to Sidekiq's `-t` if none + # is given through arguments. + DEFAULT_SOFT_TIMEOUT_SECONDS = 25 + + # After surpassing the soft timeout. + DEFAULT_HARD_TIMEOUT_SECONDS = 5 CommandError = Class.new(StandardError) @@ -74,7 +82,8 @@ module Gitlab directory: @rails_path, max_concurrency: @max_concurrency, min_concurrency: @min_concurrency, - dryrun: @dryrun + dryrun: @dryrun, + timeout: soft_timeout_seconds ) return if @dryrun @@ -88,6 +97,15 @@ module Gitlab SidekiqCluster.write_pid(@pid) if @pid end + def soft_timeout_seconds + @soft_timeout_seconds || DEFAULT_SOFT_TIMEOUT_SECONDS + end + + # The amount of time it'll wait for killing the alive Sidekiq processes. + def hard_timeout_seconds + soft_timeout_seconds + DEFAULT_HARD_TIMEOUT_SECONDS + end + def monotonic_time Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) end @@ -101,7 +119,7 @@ module Gitlab end def wait_for_termination - deadline = monotonic_time + TERMINATE_TIMEOUT_SECONDS + deadline = monotonic_time + hard_timeout_seconds sleep(CHECK_TERMINATE_INTERVAL_SECONDS) while continue_waiting?(deadline) hard_stop_stuck_pids @@ -176,6 +194,10 @@ module Gitlab @interval = int.to_i end + opt.on('-t', '--timeout INT', 'Graceful timeout for all running processes') do |timeout| + @soft_timeout_seconds = timeout.to_i + end + opt.on('-d', '--dryrun', 'Print commands that would be run without this flag, and quit') do |int| @dryrun = true end |