Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a0bede92
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,发现更多精彩内容 >>
提交
a0bede92
编写于
4月 13, 2016
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More code changes, thanks Robert
上级
525ab25a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
20 deletion
+24
-20
app/workers/repository_check_worker.rb
app/workers/repository_check_worker.rb
+12
-7
app/workers/single_repository_check_worker.rb
app/workers/single_repository_check_worker.rb
+12
-13
未找到文件。
app/workers/repository_check_worker.rb
浏览文件 @
a0bede92
...
...
@@ -25,9 +25,11 @@ class RepositoryCheckWorker
private
# In an ideal world we would use Project.where(...).find_each.
# Unfortunately, calling 'find_each' drops the 'where', so we must build
# an array of IDs instead.
# Project.find_each does not support WHERE clauses and
# Project.find_in_batches does not support ordering. So we just build an
# array of ID's. This is OK because we do it only once an hour, because
# getting ID's from Postgres is not terribly slow, and because no user
# has to sit and wait for this query to finish.
def
project_ids
limit
=
10_000
never_checked_projects
=
Project
.
where
(
'last_repository_check_at IS NULL'
).
limit
(
limit
).
...
...
@@ -40,17 +42,20 @@ class RepositoryCheckWorker
def
try_obtain_lease
(
id
)
# Use a 24-hour timeout because on servers/projects where 'git fsck' is
# super slow we definitely do not want to run it twice in parallel.
lease
=
Gitlab
::
ExclusiveLease
.
new
(
Gitlab
::
ExclusiveLease
.
new
(
"project_repository_check:
#{
id
}
"
,
timeout:
24
.
hours
)
lease
.
try_obtain
).
try_obtain
end
def
current_settings
# No caching of the settings! If we cache them and an admin disables
# this feature, an active RepositoryCheckWorker would keep going for up
# to 1 hour after the feature was disabled.
ApplicationSetting
.
current
||
Gitlab
::
CurrentSettings
.
fake_application_settings
if
Rails
.
env
.
test?
Gitlab
::
CurrentSettings
.
fake_application_settings
else
ApplicationSetting
.
current
end
end
end
app/workers/single_repository_check_worker.rb
浏览文件 @
a0bede92
...
...
@@ -5,30 +5,29 @@ class SingleRepositoryCheckWorker
def
perform
(
project_id
)
project
=
Project
.
find
(
project_id
)
update
(
project
,
success:
check
(
project
))
project
.
update_columns
(
last_repository_check_failed:
!
check
(
project
),
last_repository_check_at:
Time
.
now
,
)
end
private
def
check
(
project
)
[
project
.
repository
.
path_to_repo
,
project
.
wiki
.
wiki
.
path
].
all?
do
|
path
|
git_fsck
(
path
)
[
project
.
repository
,
project
.
wiki
.
repository
].
all?
do
|
repository
|
git_fsck
(
repository
.
path_to_repo
)
end
end
def
git_fsck
(
path
)
cmd
=
%W(nice git --git-dir=
#{
path
}
fsck)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
return
true
if
status
.
zero?
Gitlab
::
RepositoryCheckLogger
.
error
(
"command failed:
#{
cmd
.
join
(
' '
)
}
\n
#{
output
}
"
)
false
end
def
update
(
project
,
success
:)
project
.
update_columns
(
last_repository_check_failed:
!
success
,
last_repository_check_at:
Time
.
now
,
)
if
status
.
zero?
true
else
Gitlab
::
RepositoryCheckLogger
.
error
(
"command failed:
#{
cmd
.
join
(
' '
)
}
\n
#{
output
}
"
)
false
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录