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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
2a0ead2c
Commit
2a0ead2c
authored
Jul 13, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement draining scheduled sets of background migrations
parent
388abbd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
7 deletions
+30
-7
lib/gitlab/background_migration.rb
lib/gitlab/background_migration.rb
+12
-7
spec/lib/gitlab/background_migration_spec.rb
spec/lib/gitlab/background_migration_spec.rb
+14
-0
spec/support/sidekiq.rb
spec/support/sidekiq.rb
+4
-0
No files found.
lib/gitlab/background_migration.rb
View file @
2a0ead2c
module
Gitlab
module
Gitlab
module
BackgroundMigration
module
BackgroundMigration
def
self
.
queue
def
self
.
queue
BackgroundMigrationWorker
.
sidekiq_options
[
'queue'
]
@queue
||=
BackgroundMigrationWorker
.
sidekiq_options
[
'queue'
]
end
end
# Begins stealing jobs from the background migrations queue, blocking the
# Begins stealing jobs from the background migrations queue, blocking the
...
@@ -9,16 +9,20 @@ module Gitlab
...
@@ -9,16 +9,20 @@ module Gitlab
#
#
# steal_class - The name of the class for which to steal jobs.
# steal_class - The name of the class for which to steal jobs.
def
self
.
steal
(
steal_class
)
def
self
.
steal
(
steal_class
)
queue
=
Sidekiq
::
Queue
.
new
(
self
.
queue
)
enqueued
=
Sidekiq
::
Queue
.
new
(
self
.
queue
)
scheduled
=
Sidekiq
::
ScheduledSet
.
new
queue
.
each
do
|
job
|
[
scheduled
,
enqueued
].
each
do
|
queue
|
migration_class
,
migration_args
=
job
.
args
queue
.
each
do
|
job
|
migration_class
,
migration_args
=
job
.
args
next
unless
migration_class
==
steal_class
next
unless
job
.
queue
==
self
.
queue
next
unless
migration_class
==
steal_class
perform
(
migration_class
,
migration_args
)
perform
(
migration_class
,
migration_args
)
job
.
delete
job
.
delete
end
end
end
end
end
...
@@ -28,6 +32,7 @@ module Gitlab
...
@@ -28,6 +32,7 @@ module Gitlab
# arguments - The arguments to pass to the background migration's "perform"
# arguments - The arguments to pass to the background migration's "perform"
# method.
# method.
def
self
.
perform
(
class_name
,
arguments
)
def
self
.
perform
(
class_name
,
arguments
)
puts
class_name
const_get
(
class_name
).
new
.
perform
(
*
arguments
)
const_get
(
class_name
).
new
.
perform
(
*
arguments
)
end
end
end
end
...
...
spec/lib/gitlab/background_migration_spec.rb
View file @
2a0ead2c
...
@@ -34,6 +34,20 @@ describe Gitlab::BackgroundMigration do
...
@@ -34,6 +34,20 @@ describe Gitlab::BackgroundMigration do
described_class
.
steal
(
'Bar'
)
described_class
.
steal
(
'Bar'
)
end
end
end
end
context
'when there are scheduled jobs present'
,
:sidekiq
,
:redis
do
it
'steals all jobs from the schedule sets'
do
Sidekiq
::
Testing
.
disable!
do
BackgroundMigrationWorker
.
perform_in
(
10
.
minutes
,
'Object'
)
expect
(
Sidekiq
::
ScheduledSet
.
new
).
to
be_one
expect
(
described_class
).
to
receive
(
:perform
).
with
(
'Object'
,
any_args
)
described_class
.
steal
(
'Object'
)
expect
(
Sidekiq
::
ScheduledSet
.
new
).
to
be_none
end
end
end
end
end
describe
'.perform'
do
describe
'.perform'
do
...
...
spec/support/sidekiq.rb
View file @
2a0ead2c
...
@@ -8,4 +8,8 @@ RSpec.configure do |config|
...
@@ -8,4 +8,8 @@ RSpec.configure do |config|
config
.
after
(
:each
,
:sidekiq
)
do
config
.
after
(
:each
,
:sidekiq
)
do
Sidekiq
::
Worker
.
clear_all
Sidekiq
::
Worker
.
clear_all
end
end
config
.
after
(
:each
,
:sidekiq
,
:redis
)
do
Sidekiq
.
redis
{
|
redis
|
redis
.
flushdb
}
end
end
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