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
Boxiang Sun
gitlab-ce
Commits
8488c98e
Commit
8488c98e
authored
Feb 13, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schedule pipeline stages migration every 5 minutes
[ci skip]
parent
acc70f7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
db/post_migrate/20180212101928_schedule_build_stage_migration.rb
..._migrate/20180212101928_schedule_build_stage_migration.rb
+13
-5
spec/migrations/schedule_build_stage_migration_spec.rb
spec/migrations/schedule_build_stage_migration_spec.rb
+4
-10
No files found.
db/post_migrate/20180212101928_schedule_build_stage_migration.rb
View file @
8488c98e
...
...
@@ -3,18 +3,26 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration
DOWNTIME
=
false
MIGRATION
=
'MigrateBuildStage'
.
freeze
BATCH
=
1000
BATCH_SIZE
=
500
disable_ddl_transaction!
class
Build
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'ci_builds'
end
def
change
Build
.
where
(
'stage_id IS NULL'
).
each_batch
(
of:
BATCH
)
do
|
builds
,
index
|
builds
.
pluck
(
:id
).
map
{
|
id
|
[
MIGRATION
,
[
id
]]
}.
tap
do
|
migrations
|
BackgroundMigrationWorker
.
bulk_perform_in
(
index
.
minutes
,
migrations
)
def
up
disable_statement_timeout
Build
.
where
(
'stage_id IS NULL'
).
each_batch
(
of:
BATCH_SIZE
)
do
|
builds
,
index
|
builds
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
.
tap
do
|
range
|
BackgroundMigrationWorker
.
perform_in
(
index
*
5
.
minutes
,
MIGRATION
,
range
)
end
end
end
def
down
# noop
end
end
spec/migrations/schedule_build_stage_migration_spec.rb
View file @
8488c98e
...
...
@@ -8,18 +8,12 @@ describe ScheduleBuildStageMigration, :migration do
let
(
:jobs
)
{
table
(
:ci_builds
)
}
before
do
stub_const
(
"
#{
described_class
}
::BATCH"
,
1
)
stub_const
(
"
#{
described_class
}
::BATCH
_SIZE
"
,
1
)
##
# Dependencies
#
projects
.
create!
(
id:
123
,
name:
'gitlab'
,
path:
'gitlab-ce'
)
pipelines
.
create!
(
id:
1
,
project_id:
123
,
ref:
'master'
,
sha:
'adf43c3a'
)
stages
.
create!
(
id:
1
,
project_id:
123
,
pipeline_id:
1
,
name:
'test'
)
##
# CI/CD jobs
#
jobs
.
create!
(
id:
11
,
commit_id:
1
,
project_id:
123
,
stage_id:
nil
)
jobs
.
create!
(
id:
206
,
commit_id:
1
,
project_id:
123
,
stage_id:
nil
)
jobs
.
create!
(
id:
3413
,
commit_id:
1
,
project_id:
123
,
stage_id:
nil
)
...
...
@@ -31,9 +25,9 @@ describe ScheduleBuildStageMigration, :migration do
Timecop
.
freeze
do
migrate!
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
1
.
minute
,
11
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
2
.
minutes
,
206
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
3
.
minutes
,
3413
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
5
.
minutes
,
11
,
11
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
10
.
minutes
,
206
,
206
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
15
.
minutes
,
3413
,
3413
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
3
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