Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
01c55ffc
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,发现更多精彩内容 >>
提交
01c55ffc
编写于
7月 14, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Catch exceptions when stealing background migrations
上级
39b96f02
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
49 addition
and
19 deletion
+49
-19
lib/gitlab/background_migration.rb
lib/gitlab/background_migration.rb
+6
-1
spec/lib/gitlab/background_migration_spec.rb
spec/lib/gitlab/background_migration_spec.rb
+43
-18
未找到文件。
lib/gitlab/background_migration.rb
浏览文件 @
01c55ffc
...
...
@@ -19,7 +19,12 @@ module Gitlab
next
unless
job
.
queue
==
self
.
queue
next
unless
migration_class
==
steal_class
perform
(
migration_class
,
migration_args
)
if
job
.
delete
begin
perform
(
migration_class
,
migration_args
)
if
job
.
delete
rescue
=>
e
Logger
.
new
(
$stdout
).
warn
(
e
.
message
)
next
end
end
end
end
...
...
spec/lib/gitlab/background_migration_spec.rb
浏览文件 @
01c55ffc
...
...
@@ -10,40 +10,65 @@ describe Gitlab::BackgroundMigration do
describe
'.steal'
do
context
'when there are enqueued jobs present'
do
let
(
:job
)
{
double
(
:job
,
args:
[
'Foo'
,
[
10
,
20
]])
}
let
(
:queue
)
{
[
job
]
}
let
(
:queue
)
do
[
double
(
args:
[
'Foo'
,
[
10
,
20
]],
queue:
described_class
.
queue
)]
end
before
do
allow
(
Sidekiq
::
Queue
).
to
receive
(
:new
)
.
with
(
described_class
.
queue
)
.
and_return
(
queue
)
allow
(
job
).
to
receive
(
:queue
)
.
and_return
(
described_class
.
queue
)
end
it
'steals jobs from a queue'
do
expect
(
queue
[
0
]).
to
receive
(
:delete
).
and_return
(
true
)
context
'when queue contains unprocessed jobs'
do
it
'steals jobs from a queue'
do
expect
(
queue
[
0
]).
to
receive
(
:delete
).
and_return
(
true
)
expect
(
described_class
).
to
receive
(
:perform
).
with
(
'Foo'
,
[
10
,
20
])
expect
(
described_class
).
to
receive
(
:perform
).
with
(
'Foo'
,
[
10
,
20
])
described_class
.
steal
(
'Foo'
)
end
described_class
.
steal
(
'Foo'
)
end
it
'does not steal job that has already been taken'
do
expect
(
queue
[
0
]).
to
receive
(
:delete
).
and_return
(
false
)
expect
(
described_class
).
not_to
receive
(
:perform
).
with
(
'Foo'
,
[
10
,
20
])
described_class
.
steal
(
'Foo'
)
end
it
'does not steal job that has already been take
n'
do
expect
(
queue
[
0
]).
to
receive
(
:delete
).
and_return
(
false
)
it
'does not steal jobs for a different migratio
n'
do
expect
(
described_class
).
not_to
receive
(
:perform
)
expect
(
described_class
).
not_to
receive
(
:perform
).
with
(
'Foo'
,
[
10
,
20
]
)
expect
(
queue
[
0
]).
not_to
receive
(
:delete
)
described_class
.
steal
(
'Foo'
)
described_class
.
steal
(
'Bar'
)
end
end
it
'does not steal jobs for a different migration'
do
expect
(
described_class
).
not_to
receive
(
:perform
)
context
'when one of the jobs raises an error'
do
let
(
:migration
)
{
spy
(
:migration
)
}
let
(
:queue
)
do
[
double
(
args:
[
'Foo'
,
[
10
,
20
]],
queue:
described_class
.
queue
),
double
(
args:
[
'Foo'
,
[
20
,
30
]],
queue:
described_class
.
queue
)]
end
before
do
stub_const
(
"
#{
described_class
}
::Foo"
,
migration
)
expect
(
queue
[
0
]).
not_to
receive
(
:delete
)
allow
(
migration
).
to
receive
(
:perform
).
with
(
10
,
20
)
.
and_raise
(
StandardError
,
'Migration error'
)
described_class
.
steal
(
'Bar'
)
allow
(
queue
[
0
]).
to
receive
(
:delete
).
and_return
(
true
)
allow
(
queue
[
1
]).
to
receive
(
:delete
).
and_return
(
true
)
end
it
'recovers from an exceptions and continues'
do
expect
(
migration
).
to
receive
(
:perform
).
twice
expect
{
described_class
.
steal
(
'Foo'
)
}
.
to
output
(
/Migration error/
).
to_stdout
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录