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
e7f89d66
Commit
e7f89d66
authored
Mar 08, 2021
by
Matija Čupić
Committed by
Yannis Roussos
Mar 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reschedule artifact expiry backfill
parent
1cd9ee31
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
0 deletions
+88
-0
changelogs/unreleased/mc-backstage-reschedule-artifact-expiry-backfill.yml
...ased/mc-backstage-reschedule-artifact-expiry-backfill.yml
+5
-0
db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb
...ate/20210224150506_reschedule_artifact_expiry_backfill.rb
+44
-0
db/schema_migrations/20210224150506
db/schema_migrations/20210224150506
+1
-0
spec/migrations/reschedule_artifact_expiry_backfill_spec.rb
spec/migrations/reschedule_artifact_expiry_backfill_spec.rb
+38
-0
No files found.
changelogs/unreleased/mc-backstage-reschedule-artifact-expiry-backfill.yml
0 → 100644
View file @
e7f89d66
---
title
:
Reschedule artifact expiry backfill
merge_request
:
55093
author
:
type
:
changed
db/post_migrate/20210224150506_reschedule_artifact_expiry_backfill.rb
0 → 100644
View file @
e7f89d66
# frozen_string_literal: true
class
RescheduleArtifactExpiryBackfill
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
MIGRATION
=
'BackfillArtifactExpiryDate'
.
freeze
SWITCH_DATE
=
Date
.
new
(
2020
,
06
,
22
).
freeze
disable_ddl_transaction!
class
JobArtifact
<
ActiveRecord
::
Base
include
EachBatch
self
.
inheritance_column
=
:_type_disabled
self
.
table_name
=
'ci_job_artifacts'
scope
:without_expiry_date
,
->
{
where
(
expire_at:
nil
)
}
scope
:before_switch
,
->
{
where
(
"date(created_at AT TIME ZONE 'UTC') < ?::date"
,
SWITCH_DATE
)
}
end
def
up
Gitlab
::
BackgroundMigration
.
steal
(
MIGRATION
)
do
|
job
|
job
.
delete
false
end
queue_background_migration_jobs_by_range_at_intervals
(
JobArtifact
.
without_expiry_date
.
before_switch
,
MIGRATION
,
2
.
minutes
,
batch_size:
200_000
)
end
def
down
Gitlab
::
BackgroundMigration
.
steal
(
MIGRATION
)
do
|
job
|
job
.
delete
false
end
end
end
db/schema_migrations/20210224150506
0 → 100644
View file @
e7f89d66
cc9f56a872cf5e9084e863adc599545754594fb03f30f18433923e0429986e39
\ No newline at end of file
spec/migrations/reschedule_artifact_expiry_backfill_spec.rb
0 → 100644
View file @
e7f89d66
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20210224150506_reschedule_artifact_expiry_backfill.rb'
)
RSpec
.
describe
RescheduleArtifactExpiryBackfill
,
:migration
do
let
(
:migration_class
)
{
Gitlab
::
BackgroundMigration
::
BackfillArtifactExpiryDate
}
let
(
:migration_name
)
{
migration_class
.
to_s
.
demodulize
}
before
do
table
(
:namespaces
).
create!
(
id:
123
,
name:
'test_namespace'
,
path:
'test_namespace'
)
table
(
:projects
).
create!
(
id:
123
,
name:
'sample_project'
,
path:
'sample_project'
,
namespace_id:
123
)
end
it
'correctly schedules background migrations'
do
first_artifact
=
create_artifact
(
job_id:
0
,
expire_at:
nil
,
created_at:
Date
.
new
(
2020
,
06
,
21
))
second_artifact
=
create_artifact
(
job_id:
1
,
expire_at:
nil
,
created_at:
Date
.
new
(
2020
,
06
,
21
))
create_artifact
(
job_id:
2
,
expire_at:
Date
.
yesterday
,
created_at:
Date
.
new
(
2020
,
06
,
21
))
create_artifact
(
job_id:
3
,
expire_at:
nil
,
created_at:
Date
.
new
(
2020
,
06
,
23
))
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migrate!
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
1
)
expect
(
migration_name
).
to
be_scheduled_migration_with_multiple_args
(
first_artifact
.
id
,
second_artifact
.
id
)
end
end
end
private
def
create_artifact
(
params
)
table
(
:ci_builds
).
create!
(
id:
params
[
:job_id
],
project_id:
123
)
table
(
:ci_job_artifacts
).
create!
(
project_id:
123
,
file_type:
1
,
**
params
)
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