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
05f868b9
Commit
05f868b9
authored
Jan 06, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Process all projects synchronously
This simplifies things. And amount of projects are quite small.
parent
0c3092e9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
53 deletions
+30
-53
ee/db/post_migrate/20181204040404_migrate_project_approvers.rb
.../post_migrate/20181204040404_migrate_project_approvers.rb
+22
-12
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules_in_batch.rb
..._migration/migrate_approver_to_approval_rules_in_batch.rb
+4
-16
ee/spec/lib/gitlab/background_migration/migrate_approver_to_approval_rules_in_batch_spec.rb
...ation/migrate_approver_to_approval_rules_in_batch_spec.rb
+4
-25
No files found.
ee/db/post_migrate/20181204040404_migrate_project_approvers.rb
View file @
05f868b9
...
@@ -6,24 +6,25 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0]
...
@@ -6,24 +6,25 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0]
DOWNTIME
=
false
DOWNTIME
=
false
BATCH_SIZE
=
1000
BATCH_SIZE
=
1000
class
Projec
t
<
ActiveRecord
::
Base
class
MergeReques
t
<
ActiveRecord
::
Base
include
::
EachBatch
include
::
EachBatch
self
.
table_name
=
'
projec
ts'
self
.
table_name
=
'
merge_reques
ts'
end
end
def
up
class
Approver
<
ActiveRecord
::
Base
jobs
=
[]
self
.
table_name
=
'approvers'
Project
.
each_batch
(
of:
BATCH_SIZE
)
do
|
scope
|
end
project_ids
=
scope
.
pluck
(
:id
)
if
jobs
.
length
>=
BACKGROUND_MIGRATION_JOB_BUFFER_SIZE
class
ApproverGroup
<
ActiveRecord
::
Base
BackgroundMigrationWorker
.
bulk_perform_async
(
jobs
)
self
.
table_name
=
'approver_groups'
jobs
.
clear
end
end
jobs
<<
[
'MigrateApproverToApprovalRulesInBatch'
,
[
'Project'
,
project_ids
]]
def
up
get_project_ids
.
each
do
|
project_id
|
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRules
.
new
.
perform
(
'Project'
,
project_id
)
end
end
BackgroundMigrationWorker
.
bulk_perform_async
(
jobs
)
bulk_queue_background_migration_jobs_by_range
(
MergeRequest
,
'MigrateApproverToApprovalRulesInBatch'
)
check_time
=
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRulesCheckProgress
::
RESCHEDULE_DELAY
check_time
=
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRulesCheckProgress
::
RESCHEDULE_DELAY
BackgroundMigrationWorker
.
bulk_perform_in
(
check_time
,
[[
'MigrateApproverToApprovalRulesCheckProgress'
]])
BackgroundMigrationWorker
.
bulk_perform_in
(
check_time
,
[[
'MigrateApproverToApprovalRulesCheckProgress'
]])
...
@@ -31,4 +32,13 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0]
...
@@ -31,4 +32,13 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0]
def
down
def
down
end
end
private
def
get_project_ids
project_ids
=
Approver
.
where
(
'target_type = ?'
,
'Project'
).
pluck
(
:target_id
)
project_ids
+=
ApproverGroup
.
where
(
'target_type = ?'
,
'Project'
).
pluck
(
:target_id
)
project_ids
.
uniq!
project_ids
end
end
end
ee/lib/gitlab/background_migration/migrate_approver_to_approval_rules_in_batch.rb
View file @
05f868b9
...
@@ -5,25 +5,13 @@ module Gitlab
...
@@ -5,25 +5,13 @@ module Gitlab
class
MigrateApproverToApprovalRulesInBatch
class
MigrateApproverToApprovalRulesInBatch
class
MergeRequest
<
ActiveRecord
::
Base
class
MergeRequest
<
ActiveRecord
::
Base
self
.
table_name
=
'merge_requests'
self
.
table_name
=
'merge_requests'
include
::
EachBatch
end
end
def
perform
(
target_type
,
target_ids
)
def
perform
(
start_id
,
end_id
)
target_ids
.
each
do
|
target_id
|
merge_request_ids
=
MergeRequest
.
where
(
'id >= ? AND id <= ?'
,
start_id
,
end_id
).
pluck
(
:id
)
MigrateApproverToApprovalRules
.
new
.
perform
(
target_type
,
target_id
)
merge_request_ids
.
each
do
|
merge_request_id
|
MigrateApproverToApprovalRules
.
new
.
perform
(
'MergeRequest'
,
merge_request_id
)
end
end
schedule_to_migrate_merge_requests
(
target_ids
)
if
target_type
==
'Project'
end
private
def
schedule_to_migrate_merge_requests
(
project_ids
)
jobs
=
[]
MergeRequest
.
where
(
target_project_id:
project_ids
).
each_batch
do
|
scope
,
_
|
jobs
<<
[
self
.
class
.
name
,
[
'MergeRequest'
,
scope
.
pluck
(
:id
)]]
end
BackgroundMigrationWorker
.
bulk_perform_async
(
jobs
)
unless
jobs
.
empty?
end
end
end
end
end
end
...
...
ee/spec/lib/gitlab/background_migration/migrate_approver_to_approval_rules_in_batch_spec.rb
View file @
05f868b9
...
@@ -5,37 +5,16 @@ require 'spec_helper'
...
@@ -5,37 +5,16 @@ require 'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRulesInBatch
do
describe
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRulesInBatch
do
context
'when there is no more MigrateApproverToApprovalRules jobs'
do
context
'when there is no more MigrateApproverToApprovalRules jobs'
do
let
(
:job
)
{
double
(
:job
)
}
let
(
:job
)
{
double
(
:job
)
}
let
(
:project
)
{
create
(
:project
)
}
it
'migrates individual target'
do
it
'migrates individual target'
do
allow
(
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRules
).
to
receive
(
:new
).
and_return
(
job
)
allow
(
Gitlab
::
BackgroundMigration
::
MigrateApproverToApprovalRules
).
to
receive
(
:new
).
and_return
(
job
)
expect
(
job
).
to
receive
(
:perform
).
exactly
(
3
).
times
merge_requests
=
create_list
(
:merge_request
,
3
)
described_class
.
new
.
perform
(
'Foo'
,
[
1
,
2
,
3
])
end
context
'when targets are projects'
do
let
(
:projects
)
{
create_list
(
:project
,
3
)
}
context
'when projects contain merge requests'
do
expect
(
job
).
to
receive
(
:perform
).
exactly
(
3
).
times
it
'schedules migrations for merge requests'
do
merge_requests
=
projects
.
flat_map
do
|
project
|
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
expect
(
BackgroundMigrationWorker
).
to
receive
(
:bulk_perform_async
).
with
([[
described_class
.
name
,
[
"MergeRequest"
,
merge_requests
.
map
(
&
:id
)]]])
described_class
.
new
.
perform
(
'Project'
,
projects
.
map
(
&
:id
))
end
end
context
'when merge request do not exist'
do
it
'does nothing'
do
expect
(
BackgroundMigrationWorker
).
not_to
receive
(
:bulk_perform_async
)
described_class
.
new
.
perform
(
'Project'
,
projects
.
map
(
&
:id
))
described_class
.
new
.
perform
(
merge_requests
.
first
.
id
,
merge_requests
.
last
.
id
)
end
end
end
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