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
Jérome Perrin
gitlab-ce
Commits
193b1996
Commit
193b1996
authored
Aug 22, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Sidekiq migration helpers for migrating queues
parent
73187801
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
3 deletions
+62
-3
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+14
-0
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+48
-3
No files found.
lib/gitlab/database/migration_helpers.rb
View file @
193b1996
...
...
@@ -611,6 +611,20 @@ module Gitlab
remove_foreign_key
(
*
args
)
rescue
ArgumentError
end
def
sidekiq_queue_migrate
(
queue_from
,
to:
queue_to
)
while
sidekiq_queue_length
(
queue_from
)
>
0
Sidekiq
.
redis
do
|
conn
|
conn
.
rpoplpush
"queue:
#{
queue_from
}
"
,
"queue:
#{
to
}
"
end
end
end
def
sidekiq_queue_length
(
queue_name
)
Sidekiq
.
redis
do
|
conn
|
conn
.
llen
(
"queue:
#{
queue_name
}
"
)
end
end
end
end
end
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
193b1996
...
...
@@ -2,9 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Database
::
MigrationHelpers
do
let
(
:model
)
do
ActiveRecord
::
Migration
.
new
.
extend
(
described_class
)
ActiveRecord
::
Migration
.
new
.
extend
(
described_class
)
end
before
do
...
...
@@ -845,4 +843,51 @@ describe Gitlab::Database::MigrationHelpers do
end
end
end
describe
'sidekiq migration helpers'
,
:sidekiq
,
:redis
do
let
(
:worker
)
do
Class
.
new
do
include
Sidekiq
::
Worker
sidekiq_options
queue:
'test'
end
end
describe
'#sidekiq_queue_length'
do
context
'when queue is empty'
do
it
'returns zero'
do
Sidekiq
::
Testing
.
disable!
do
expect
(
model
.
sidekiq_queue_length
(
'test'
)).
to
eq
0
end
end
end
context
'when queue contains jobs'
do
it
'returns correct size of the queue'
do
Sidekiq
::
Testing
.
disable!
do
worker
.
perform_async
(
'Something'
,
[
1
])
worker
.
perform_async
(
'Something'
,
[
2
])
expect
(
model
.
sidekiq_queue_length
(
'test'
)).
to
eq
2
end
end
end
end
describe
'#migrate_sidekiq_queue'
do
it
'migrates jobs from one sidekiq queue to another'
do
Sidekiq
::
Testing
.
disable!
do
worker
.
perform_async
(
'Something'
,
[
1
])
worker
.
perform_async
(
'Something'
,
[
2
])
expect
(
model
.
sidekiq_queue_length
(
'test'
)).
to
eq
2
expect
(
model
.
sidekiq_queue_length
(
'new_test'
)).
to
eq
0
model
.
sidekiq_queue_migrate
(
'test'
,
to:
'new_test'
)
expect
(
model
.
sidekiq_queue_length
(
'test'
)).
to
eq
0
expect
(
model
.
sidekiq_queue_length
(
'new_test'
)).
to
eq
2
end
end
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