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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
a0bede92
Commit
a0bede92
authored
Apr 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More code changes, thanks Robert
parent
525ab25a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
20 deletions
+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
No files found.
app/workers/repository_check_worker.rb
View file @
a0bede92
...
@@ -25,9 +25,11 @@ class RepositoryCheckWorker
...
@@ -25,9 +25,11 @@ class RepositoryCheckWorker
private
private
# In an ideal world we would use Project.where(...).find_each.
# Project.find_each does not support WHERE clauses and
# Unfortunately, calling 'find_each' drops the 'where', so we must build
# Project.find_in_batches does not support ordering. So we just build an
# an array of IDs instead.
# 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
def
project_ids
limit
=
10_000
limit
=
10_000
never_checked_projects
=
Project
.
where
(
'last_repository_check_at IS NULL'
).
limit
(
limit
).
never_checked_projects
=
Project
.
where
(
'last_repository_check_at IS NULL'
).
limit
(
limit
).
...
@@ -40,17 +42,20 @@ class RepositoryCheckWorker
...
@@ -40,17 +42,20 @@ class RepositoryCheckWorker
def
try_obtain_lease
(
id
)
def
try_obtain_lease
(
id
)
# Use a 24-hour timeout because on servers/projects where 'git fsck' is
# 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.
# super slow we definitely do not want to run it twice in parallel.
lease
=
Gitlab
::
ExclusiveLease
.
new
(
Gitlab
::
ExclusiveLease
.
new
(
"project_repository_check:
#{
id
}
"
,
"project_repository_check:
#{
id
}
"
,
timeout:
24
.
hours
timeout:
24
.
hours
)
).
try_obtain
lease
.
try_obtain
end
end
def
current_settings
def
current_settings
# No caching of the settings! If we cache them and an admin disables
# No caching of the settings! If we cache them and an admin disables
# this feature, an active RepositoryCheckWorker would keep going for up
# this feature, an active RepositoryCheckWorker would keep going for up
# to 1 hour after the feature was disabled.
# 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
end
end
app/workers/single_repository_check_worker.rb
View file @
a0bede92
...
@@ -5,30 +5,29 @@ class SingleRepositoryCheckWorker
...
@@ -5,30 +5,29 @@ class SingleRepositoryCheckWorker
def
perform
(
project_id
)
def
perform
(
project_id
)
project
=
Project
.
find
(
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
end
private
private
def
check
(
project
)
def
check
(
project
)
[
project
.
repository
.
path_to_repo
,
project
.
wiki
.
wiki
.
path
].
all?
do
|
path
|
[
project
.
repository
,
project
.
wiki
.
repository
].
all?
do
|
repository
|
git_fsck
(
path
)
git_fsck
(
repository
.
path_to_repo
)
end
end
end
end
def
git_fsck
(
path
)
def
git_fsck
(
path
)
cmd
=
%W(nice git --git-dir=
#{
path
}
fsck)
cmd
=
%W(nice git --git-dir=
#{
path
}
fsck)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
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
:)
if
status
.
zero?
project
.
update_columns
(
true
last_repository_check_failed:
!
success
,
else
last_repository_check_at:
Time
.
now
,
Gitlab
::
RepositoryCheckLogger
.
error
(
"command failed:
#{
cmd
.
join
(
' '
)
}
\n
#{
output
}
"
)
)
false
end
end
end
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