Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5711eeed
Commit
5711eeed
authored
Dec 01, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `--dryrun` option to `bin/sidekiq-cluster`, and spec to verify it actually runs
parent
c5bd57e8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
16 deletions
+43
-16
lib/gitlab/sidekiq_cluster.rb
lib/gitlab/sidekiq_cluster.rb
+18
-12
lib/gitlab/sidekiq_cluster/cli.rb
lib/gitlab/sidekiq_cluster/cli.rb
+8
-1
spec/bin/sidekiq_cluster_spec.rb
spec/bin/sidekiq_cluster_spec.rb
+14
-0
spec/lib/gitlab/sidekiq_cluster/cli_spec.rb
spec/lib/gitlab/sidekiq_cluster/cli_spec.rb
+1
-1
spec/lib/gitlab/sidekiq_cluster_spec.rb
spec/lib/gitlab/sidekiq_cluster_spec.rb
+2
-2
No files found.
lib/gitlab/sidekiq_cluster.rb
View file @
5711eeed
...
...
@@ -62,26 +62,32 @@ module Gitlab
# directory - The directory of the Rails application.
#
# Returns an Array containing the PIDs of the started processes.
def
self
.
start
(
queues
,
env
,
directory
=
Dir
.
pwd
)
queues
.
map
{
|
pair
|
start_sidekiq
(
pair
,
env
,
directory
)
}
def
self
.
start
(
queues
,
env
,
directory
=
Dir
.
pwd
,
dryrun:
false
)
queues
.
map
{
|
pair
|
start_sidekiq
(
pair
,
env
,
directory
,
dryrun:
dryrun
)
}
end
# Starts a Sidekiq process that processes _only_ the given queues.
#
# Returns the PID of the started process.
def
self
.
start_sidekiq
(
queues
,
env
,
directory
=
Dir
.
pwd
)
switches
=
queues
.
map
{
|
q
|
"-q
#{
q
}
,1"
}
def
self
.
start_sidekiq
(
queues
,
env
,
directory
=
Dir
.
pwd
,
dryrun:
false
)
cmd
=
%w[bundle exec sidekiq]
cmd
<<
"-c
#{
queues
.
length
+
1
}
"
cmd
<<
"-e
#{
env
}
"
cmd
<<
"-gqueues:
#{
queues
.
join
(
', '
)
}
"
cmd
<<
"-r
#{
directory
}
"
queues
.
each
do
|
q
|
cmd
<<
"-q
#{
q
}
,1"
end
if
dryrun
puts
"Sidekiq command:
#{
cmd
}
"
# rubocop:disable Rails/Output
return
end
pid
=
Process
.
spawn
(
{
'ENABLE_SIDEKIQ_CLUSTER'
=>
'1'
},
'bundle'
,
'exec'
,
'sidekiq'
,
"-c
#{
queues
.
length
+
1
}
"
,
"-e
#{
env
}
"
,
"-gqueues:
#{
queues
.
join
(
', '
)
}
"
,
"-r
#{
directory
}
"
,
*
switches
,
*
cmd
,
err:
$stderr
,
out:
$stdout
)
...
...
lib/gitlab/sidekiq_cluster/cli.rb
View file @
5711eeed
...
...
@@ -15,6 +15,7 @@ module Gitlab
@processes
=
[]
@logger
=
Logger
.
new
(
log_output
)
@rails_path
=
Dir
.
pwd
@dryrun
=
false
# Use a log format similar to Sidekiq to make parsing/grepping easier.
@logger
.
formatter
=
proc
do
|
level
,
date
,
program
,
message
|
...
...
@@ -39,7 +40,9 @@ module Gitlab
@logger
.
info
(
"Starting cluster with
#{
queue_groups
.
length
}
processes"
)
@processes
=
SidekiqCluster
.
start
(
queue_groups
,
@environment
,
@rails_path
)
@processes
=
SidekiqCluster
.
start
(
queue_groups
,
@environment
,
@rails_path
,
dryrun:
@dryrun
)
return
if
@dryrun
write_pid
trap_signals
...
...
@@ -105,6 +108,10 @@ module Gitlab
opt
.
on
(
'-i'
,
'--interval INT'
,
'The number of seconds to wait between worker checks'
)
do
|
int
|
@interval
=
int
.
to_i
end
opt
.
on
(
'-d'
,
'--dryrun'
,
'Print commands that would be run without this flag, and quit'
)
do
|
int
|
@dryrun
=
true
end
end
end
end
...
...
spec/bin/sidekiq_cluster_spec.rb
0 → 100644
View file @
5711eeed
require
'spec_helper'
describe
'bin/sidekiq-cluster'
do
it
'runs successfully'
,
:aggregate_failures
do
cmd
=
%w[bin/sidekiq-cluster --dryrun --negate cronjob]
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
,
Rails
.
root
.
to_s
)
expect
(
status
).
to
be
(
0
)
expect
(
output
).
to
include
(
'"bundle", "exec", "sidekiq"'
)
expect
(
output
).
not_to
include
(
'-qcronjob,1'
)
expect
(
output
).
to
include
(
'-qdefault,1'
)
end
end
spec/lib/gitlab/sidekiq_cluster/cli_spec.rb
View file @
5711eeed
...
...
@@ -24,7 +24,7 @@ describe Gitlab::SidekiqCluster::CLI do
it
'starts Sidekiq workers for all queues on sidekiq_queues.yml except the ones on argv'
do
expect
(
Gitlab
::
SidekiqConfig
).
to
receive
(
:config_queues
).
and_return
([
'baz'
])
expect
(
Gitlab
::
SidekiqCluster
).
to
receive
(
:start
)
.
with
([[
'baz'
]],
'test'
,
Dir
.
pwd
)
.
with
([[
'baz'
]],
'test'
,
Dir
.
pwd
,
dryrun:
false
)
.
and_return
([])
expect
(
cli
).
to
receive
(
:write_pid
)
expect
(
cli
).
to
receive
(
:trap_signals
)
...
...
spec/lib/gitlab/sidekiq_cluster_spec.rb
View file @
5711eeed
...
...
@@ -58,10 +58,10 @@ describe Gitlab::SidekiqCluster do
describe
'.start'
do
it
'starts Sidekiq with the given queues and environment'
do
expect
(
described_class
).
to
receive
(
:start_sidekiq
)
.
ordered
.
with
(
%w(foo)
,
:production
,
'foo/bar'
)
.
ordered
.
with
(
%w(foo)
,
:production
,
'foo/bar'
,
dryrun:
false
)
expect
(
described_class
).
to
receive
(
:start_sidekiq
)
.
ordered
.
with
(
%w(bar baz)
,
:production
,
'foo/bar'
)
.
ordered
.
with
(
%w(bar baz)
,
:production
,
'foo/bar'
,
dryrun:
false
)
described_class
.
start
([
%w(foo)
,
%w(bar baz)
],
:production
,
'foo/bar'
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment