Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4f24a65e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f24a65e
编写于
3月 29, 2018
作者:
M
Micaël Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the rake task from being to strict about Group
上级
80ef79f2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
116 addition
and
16 deletion
+116
-16
app/workers/object_storage/migrate_uploads_worker.rb
app/workers/object_storage/migrate_uploads_worker.rb
+7
-9
lib/tasks/gitlab/uploads/migrate.rake
lib/tasks/gitlab/uploads/migrate.rake
+1
-0
spec/tasks/gitlab/uploads/migrate_rake_spec.rb
spec/tasks/gitlab/uploads/migrate_rake_spec.rb
+108
-7
未找到文件。
app/workers/object_storage/migrate_uploads_worker.rb
浏览文件 @
4f24a65e
...
...
@@ -138,21 +138,18 @@ module ObjectStorage
include
Report
def
self
.
enqueue!
(
uploads
,
mounted_as
,
to_store
)
sanity_check!
(
uploads
,
mounted_as
)
def
self
.
enqueue!
(
uploads
,
mo
del_class
,
mo
unted_as
,
to_store
)
sanity_check!
(
uploads
,
mo
del_class
,
mo
unted_as
)
perform_async
(
uploads
.
ids
,
mounted_as
,
to_store
)
perform_async
(
uploads
.
ids
,
mo
del_class
.
to_s
,
mo
unted_as
,
to_store
)
end
# We need to be sure all the uploads are for the same uploader and model type
# and that the mount point exists if provided.
#
def
self
.
sanity_check!
(
uploads
,
mounted_as
)
def
self
.
sanity_check!
(
uploads
,
mo
del_class
,
mo
unted_as
)
upload
=
uploads
.
first
uploader_class
=
upload
.
uploader
.
constantize
model_class
=
uploads
.
first
.
model_type
.
constantize
uploader_types
=
uploads
.
map
(
&
:uploader
).
uniq
model_types
=
uploads
.
map
(
&
:model_type
).
uniq
model_has_mount
=
mounted_as
.
nil?
||
model_class
.
uploaders
[
mounted_as
]
==
uploader_class
...
...
@@ -162,7 +159,8 @@ module ObjectStorage
raise
(
SanityCheckError
,
"Mount point
#{
mounted_as
}
not found in
#{
model_class
}
."
)
unless
model_has_mount
end
def
perform
(
ids
,
mounted_as
,
to_store
)
def
perform
(
ids
,
model_type
,
mounted_as
,
to_store
)
@model_class
=
model_type
.
constantize
@mounted_as
=
mounted_as
&
.
to_sym
@to_store
=
to_store
...
...
@@ -178,7 +176,7 @@ module ObjectStorage
end
def
sanity_check!
(
uploads
)
self
.
class
.
sanity_check!
(
uploads
,
@mounted_as
)
self
.
class
.
sanity_check!
(
uploads
,
@mo
del_class
,
@mo
unted_as
)
end
def
build_uploaders
(
uploads
)
...
...
lib/tasks/gitlab/uploads/migrate.rake
浏览文件 @
4f24a65e
...
...
@@ -13,6 +13,7 @@ namespace :gitlab do
def
enqueue_batch
(
batch
,
index
)
job
=
ObjectStorage
::
MigrateUploadsWorker
.
enqueue!
(
batch
,
@model_class
,
@mounted_as
,
@to_store
)
puts
"Enqueued job #
#{
index
}
:
#{
job
}
"
...
...
spec/tasks/gitlab/uploads/migrate_rake_spec.rb
浏览文件 @
4f24a65e
require
'rake_helper'
describe
'gitlab:uploads:migrate rake tasks'
do
let!
(
:projects
)
{
create_list
(
:project
,
10
,
:with_avatar
)
}
let
(
:model_class
)
{
Project
}
let
(
:uploader_class
)
{
AvatarUploader
}
let
(
:mounted_as
)
{
:avatar
}
let
(
:model_class
)
{
nil
}
let
(
:uploader_class
)
{
nil
}
let
(
:mounted_as
)
{
nil
}
let
(
:batch_size
)
{
3
}
before
do
...
...
@@ -30,11 +29,113 @@ describe 'gitlab:uploads:migrate rake tasks' do
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
context
"for AvatarUploader"
do
let
(
:uploader_class
)
{
AvatarUploader
}
let
(
:mounted_as
)
{
:avatar
}
context
"for Project"
do
let
(
:model_class
)
{
Project
}
let!
(
:projects
)
{
create_list
(
:project
,
10
,
:with_avatar
)
}
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
context
'Upload has store = nil'
do
before
do
Upload
.
where
(
model:
projects
).
update_all
(
store:
nil
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
end
context
"for Group"
do
let
(
:model_class
)
{
Group
}
before
do
create_list
(
:group
,
10
,
:with_avatar
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for User"
do
let
(
:model_class
)
{
User
}
before
do
create_list
(
:user
,
10
,
:with_avatar
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
end
context
"for AttachmentUploader"
do
let
(
:uploader_class
)
{
AttachmentUploader
}
context
"for Note"
do
let
(
:model_class
)
{
Note
}
let
(
:mounted_as
)
{
:attachment
}
before
do
create_list
(
:note
,
10
,
:with_attachment
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for Appearance"
do
let
(
:model_class
)
{
Appearance
}
let
(
:mounted_as
)
{
:logo
}
before
do
create
(
:appearance
,
:with_logos
)
end
%i(logo header_logo)
.
each
do
|
mount
|
it_behaves_like
'enqueue jobs in batch'
,
batch:
1
do
let
(
:mounted_as
)
{
mount
}
end
end
end
end
context
"for FileUploader"
do
let
(
:uploader_class
)
{
FileUploader
}
let
(
:model_class
)
{
Project
}
before
do
create_list
(
:project
,
10
)
do
|
model
|
uploader_class
.
new
(
model
)
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for PersonalFileUploader"
do
let
(
:uploader_class
)
{
PersonalFileUploader
}
let
(
:model_class
)
{
PersonalSnippet
}
before
do
create_list
(
:personal_snippet
,
10
)
do
|
model
|
uploader_class
.
new
(
model
)
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for NamespaceFileUploader"
do
let
(
:uploader_class
)
{
NamespaceFileUploader
}
let
(
:model_class
)
{
Snippet
}
context
'Upload has store = nil'
do
before
do
Upload
.
where
(
model:
projects
).
update_all
(
store:
nil
)
create_list
(
:snippet
,
10
)
do
|
model
|
uploader_class
.
new
(
model
)
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录