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
93148873
Commit
93148873
authored
Jan 19, 2021
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cleanup rake task limit
Methods defined in rake tasks are defined globally.
parent
7916beef
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
42 deletions
+33
-42
changelogs/unreleased/mk-fix-cleanup-rake-task-limit.yml
changelogs/unreleased/mk-fix-cleanup-rake-task-limit.yml
+5
-0
lib/gitlab/cleanup/orphan_job_artifact_files.rb
lib/gitlab/cleanup/orphan_job_artifact_files.rb
+11
-4
lib/gitlab/cleanup/orphan_lfs_file_references.rb
lib/gitlab/cleanup/orphan_lfs_file_references.rb
+6
-3
lib/tasks/gitlab/cleanup.rake
lib/tasks/gitlab/cleanup.rake
+2
-7
lib/tasks/gitlab/snippets.rake
lib/tasks/gitlab/snippets.rake
+6
-6
spec/lib/gitlab/cleanup/orphan_job_artifact_files_spec.rb
spec/lib/gitlab/cleanup/orphan_job_artifact_files_spec.rb
+2
-1
spec/tasks/gitlab/cleanup_rake_spec.rb
spec/tasks/gitlab/cleanup_rake_spec.rb
+1
-21
No files found.
changelogs/unreleased/mk-fix-cleanup-rake-task-limit.yml
0 → 100644
View file @
93148873
---
title
:
Fix gitlab:cleanup:orphan_job_artifact_files rake task limit
merge_request
:
52056
author
:
type
:
fixed
lib/gitlab/cleanup/orphan_job_artifact_files.rb
View file @
93148873
...
@@ -12,10 +12,9 @@ module Gitlab
...
@@ -12,10 +12,9 @@ module Gitlab
VALID_NICENESS_LEVELS
=
%w{none realtime best-effort idle}
.
freeze
VALID_NICENESS_LEVELS
=
%w{none realtime best-effort idle}
.
freeze
attr_accessor
:batch
,
:total_found
,
:total_cleaned
attr_accessor
:batch
,
:total_found
,
:total_cleaned
attr_reader
:
limit
,
:
dry_run
,
:niceness
,
:logger
attr_reader
:dry_run
,
:niceness
,
:logger
def
initialize
(
limit:
nil
,
dry_run:
true
,
niceness:
nil
,
logger:
nil
)
def
initialize
(
dry_run:
true
,
niceness:
nil
,
logger:
nil
)
@limit
=
limit
@dry_run
=
dry_run
@dry_run
=
dry_run
@niceness
=
(
niceness
||
DEFAULT_NICENESS
).
downcase
@niceness
=
(
niceness
||
DEFAULT_NICENESS
).
downcase
@logger
=
logger
||
Gitlab
::
AppLogger
@logger
=
logger
||
Gitlab
::
AppLogger
...
@@ -31,7 +30,11 @@ module Gitlab
...
@@ -31,7 +30,11 @@ module Gitlab
batch
<<
artifact_file
batch
<<
artifact_file
clean_batch!
if
batch
.
full?
clean_batch!
if
batch
.
full?
break
if
limit_reached?
if
limit_reached?
log_info
(
"Exiting due to reaching limit of
#{
limit
}
."
)
break
end
end
end
clean_batch!
clean_batch!
...
@@ -128,6 +131,10 @@ module Gitlab
...
@@ -128,6 +131,10 @@ module Gitlab
def
log_error
(
msg
,
params
=
{})
def
log_error
(
msg
,
params
=
{})
logger
.
error
(
msg
)
logger
.
error
(
msg
)
end
end
def
limit
ENV
[
'LIMIT'
]
&
.
to_i
end
end
end
end
end
end
end
...
...
lib/gitlab/cleanup/orphan_lfs_file_references.rb
View file @
93148873
...
@@ -5,15 +5,14 @@ module Gitlab
...
@@ -5,15 +5,14 @@ module Gitlab
class
OrphanLfsFileReferences
class
OrphanLfsFileReferences
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:project
,
:dry_run
,
:logger
,
:limit
attr_reader
:project
,
:dry_run
,
:logger
DEFAULT_REMOVAL_LIMIT
=
1000
DEFAULT_REMOVAL_LIMIT
=
1000
def
initialize
(
project
,
dry_run:
true
,
logger:
nil
,
limit:
nil
)
def
initialize
(
project
,
dry_run:
true
,
logger:
nil
)
@project
=
project
@project
=
project
@dry_run
=
dry_run
@dry_run
=
dry_run
@logger
=
logger
||
Gitlab
::
AppLogger
@logger
=
logger
||
Gitlab
::
AppLogger
@limit
=
limit
end
end
def
run!
def
run!
...
@@ -67,6 +66,10 @@ module Gitlab
...
@@ -67,6 +66,10 @@ module Gitlab
def
log_info
(
msg
)
def
log_info
(
msg
)
logger
.
info
(
"
#{
'[DRY RUN] '
if
dry_run
}#{
msg
}
"
)
logger
.
info
(
"
#{
'[DRY RUN] '
if
dry_run
}#{
msg
}
"
)
end
end
def
limit
ENV
[
'LIMIT'
]
&
.
to_i
end
end
end
end
end
end
end
lib/tasks/gitlab/cleanup.rake
View file @
93148873
...
@@ -56,7 +56,7 @@ namespace :gitlab do
...
@@ -56,7 +56,7 @@ namespace :gitlab do
task
orphan_job_artifact_files: :gitlab_environment
do
task
orphan_job_artifact_files: :gitlab_environment
do
warn_user_is_not_gitlab
warn_user_is_not_gitlab
cleaner
=
Gitlab
::
Cleanup
::
OrphanJobArtifactFiles
.
new
(
limit:
limit
,
dry_run:
dry_run?
,
niceness:
niceness
,
logger:
logger
)
cleaner
=
Gitlab
::
Cleanup
::
OrphanJobArtifactFiles
.
new
(
dry_run:
dry_run?
,
niceness:
niceness
,
logger:
logger
)
cleaner
.
run!
cleaner
.
run!
if
dry_run?
if
dry_run?
...
@@ -78,8 +78,7 @@ namespace :gitlab do
...
@@ -78,8 +78,7 @@ namespace :gitlab do
cleaner
=
Gitlab
::
Cleanup
::
OrphanLfsFileReferences
.
new
(
cleaner
=
Gitlab
::
Cleanup
::
OrphanLfsFileReferences
.
new
(
project
,
project
,
dry_run:
dry_run?
,
dry_run:
dry_run?
,
logger:
logger
,
logger:
logger
limit:
limit
)
)
cleaner
.
run!
cleaner
.
run!
...
@@ -162,10 +161,6 @@ namespace :gitlab do
...
@@ -162,10 +161,6 @@ namespace :gitlab do
ENV
[
'DEBUG'
].
present?
ENV
[
'DEBUG'
].
present?
end
end
def
limit
ENV
[
'LIMIT'
]
&
.
to_i
end
def
niceness
def
niceness
ENV
[
'NICENESS'
].
presence
ENV
[
'NICENESS'
].
presence
end
end
...
...
lib/tasks/gitlab/snippets.rake
View file @
93148873
...
@@ -13,7 +13,7 @@ namespace :gitlab do
...
@@ -13,7 +13,7 @@ namespace :gitlab do
raise
"Please supply the list of ids through the SNIPPET_IDS env var"
raise
"Please supply the list of ids through the SNIPPET_IDS env var"
end
end
raise
"Invalid limit value"
if
limit
==
0
raise
"Invalid limit value"
if
snippet_task_
limit
==
0
if
migration_running?
if
migration_running?
raise
"There are already snippet migrations running. Please wait until they are finished."
raise
"There are already snippet migrations running. Please wait until they are finished."
...
@@ -41,8 +41,8 @@ namespace :gitlab do
...
@@ -41,8 +41,8 @@ namespace :gitlab do
end
end
end
end
if
ids
.
size
>
limit
if
ids
.
size
>
snippet_task_
limit
raise
"The number of ids provided is higher than
#{
limit
}
. You can update this limit by using the env var `LIMIT`"
raise
"The number of ids provided is higher than
#{
snippet_task_
limit
}
. You can update this limit by using the env var `LIMIT`"
end
end
ids
ids
...
@@ -68,14 +68,14 @@ namespace :gitlab do
...
@@ -68,14 +68,14 @@ namespace :gitlab do
# bundle exec rake gitlab:snippets:list_non_migrated LIMIT=50
# bundle exec rake gitlab:snippets:list_non_migrated LIMIT=50
desc
'GitLab | Show non migrated snippets'
desc
'GitLab | Show non migrated snippets'
task
list_non_migrated: :environment
do
task
list_non_migrated: :environment
do
raise
"Invalid limit value"
if
limit
==
0
raise
"Invalid limit value"
if
snippet_task_
limit
==
0
non_migrated_count
=
non_migrated_snippets
.
count
non_migrated_count
=
non_migrated_snippets
.
count
if
non_migrated_count
==
0
if
non_migrated_count
==
0
puts
"All snippets have been successfully migrated"
puts
"All snippets have been successfully migrated"
else
else
puts
"There are
#{
non_migrated_count
}
snippets that haven't been migrated. Showing a batch of ids of those snippets:
\n
"
puts
"There are
#{
non_migrated_count
}
snippets that haven't been migrated. Showing a batch of ids of those snippets:
\n
"
puts
non_migrated_snippets
.
limit
(
limit
).
pluck
(
:id
).
join
(
','
)
puts
non_migrated_snippets
.
limit
(
snippet_task_
limit
).
pluck
(
:id
).
join
(
','
)
end
end
end
end
...
@@ -84,7 +84,7 @@ namespace :gitlab do
...
@@ -84,7 +84,7 @@ namespace :gitlab do
end
end
# There are problems with the specs if we memoize this value
# There are problems with the specs if we memoize this value
def
limit
def
snippet_task_
limit
ENV
[
'LIMIT'
]
?
ENV
[
'LIMIT'
].
to_i
:
DEFAULT_LIMIT
ENV
[
'LIMIT'
]
?
ENV
[
'LIMIT'
].
to_i
:
DEFAULT_LIMIT
end
end
end
end
...
...
spec/lib/gitlab/cleanup/orphan_job_artifact_files_spec.rb
View file @
93148873
...
@@ -42,7 +42,8 @@ RSpec.describe Gitlab::Cleanup::OrphanJobArtifactFiles do
...
@@ -42,7 +42,8 @@ RSpec.describe Gitlab::Cleanup::OrphanJobArtifactFiles do
end
end
it
'stops when limit is reached'
do
it
'stops when limit is reached'
do
cleanup
=
described_class
.
new
(
limit:
1
)
stub_env
(
'LIMIT'
,
1
)
cleanup
=
described_class
.
new
mock_artifacts_found
(
cleanup
,
'tmp/foo/bar/1'
,
'tmp/foo/bar/2'
)
mock_artifacts_found
(
cleanup
,
'tmp/foo/bar/1'
,
'tmp/foo/bar/2'
)
...
...
spec/tasks/gitlab/cleanup_rake_spec.rb
View file @
93148873
...
@@ -109,8 +109,7 @@ RSpec.describe 'gitlab:cleanup rake tasks' do
...
@@ -109,8 +109,7 @@ RSpec.describe 'gitlab:cleanup rake tasks' do
it
'passes dry_run correctly'
do
it
'passes dry_run correctly'
do
expect
(
Gitlab
::
Cleanup
::
OrphanJobArtifactFiles
)
expect
(
Gitlab
::
Cleanup
::
OrphanJobArtifactFiles
)
.
to
receive
(
:new
)
.
to
receive
(
:new
)
.
with
(
limit:
anything
,
.
with
(
dry_run:
false
,
dry_run:
false
,
niceness:
anything
,
niceness:
anything
,
logger:
anything
)
logger:
anything
)
.
and_call_original
.
and_call_original
...
@@ -145,7 +144,6 @@ RSpec.describe 'gitlab:cleanup rake tasks' do
...
@@ -145,7 +144,6 @@ RSpec.describe 'gitlab:cleanup rake tasks' do
expect
(
Gitlab
::
Cleanup
::
OrphanLfsFileReferences
)
expect
(
Gitlab
::
Cleanup
::
OrphanLfsFileReferences
)
.
to
receive
(
:new
)
.
to
receive
(
:new
)
.
with
(
project
,
.
with
(
project
,
limit:
anything
,
dry_run:
false
,
dry_run:
false
,
logger:
anything
)
logger:
anything
)
.
and_call_original
.
and_call_original
...
@@ -153,24 +151,6 @@ RSpec.describe 'gitlab:cleanup rake tasks' do
...
@@ -153,24 +151,6 @@ RSpec.describe 'gitlab:cleanup rake tasks' do
rake_task
rake_task
end
end
end
end
context
'with LIMIT set to 100'
do
before
do
stub_env
(
'LIMIT'
,
'100'
)
end
it
'passes limit as integer'
do
expect
(
Gitlab
::
Cleanup
::
OrphanLfsFileReferences
)
.
to
receive
(
:new
)
.
with
(
project
,
limit:
100
,
dry_run:
true
,
logger:
anything
)
.
and_call_original
rake_task
end
end
end
end
describe
'gitlab:cleanup:orphan_lfs_files'
do
describe
'gitlab:cleanup:orphan_lfs_files'
do
...
...
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