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
Boxiang Sun
gitlab-ce
Commits
43a359ab
Commit
43a359ab
authored
Feb 23, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify project import status again before marking as failed
parent
e610f960
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
31 deletions
+48
-31
app/workers/stuck_import_jobs_worker.rb
app/workers/stuck_import_jobs_worker.rb
+12
-14
changelogs/unreleased/dm-stuck-import-jobs-verify.yml
changelogs/unreleased/dm-stuck-import-jobs-verify.yml
+5
-0
spec/workers/stuck_import_jobs_worker_spec.rb
spec/workers/stuck_import_jobs_worker_spec.rb
+31
-17
No files found.
app/workers/stuck_import_jobs_worker.rb
View file @
43a359ab
...
...
@@ -22,25 +22,23 @@ class StuckImportJobsWorker
end
def
mark_projects_with_jid_as_failed!
completed_jids_count
=
0
jids_and_ids
=
enqueued_projects_with_jid
.
pluck
(
:import_jid
,
:id
).
to_h
enqueued_projects_with_jid
.
find_in_batches
(
batch_size:
500
)
do
|
group
|
jids
=
group
.
map
(
&
:import_jid
)
# Find the jobs that aren't currently running or that exceeded the threshold.
completed_jids
=
Gitlab
::
SidekiqStatus
.
completed_jids
(
jids_and_ids
.
keys
)
return
unless
completed_jids
.
any?
# Find the jobs that aren't currently running or that exceeded the threshold.
completed_jids
=
Gitlab
::
SidekiqStatus
.
completed_jids
(
jids
).
to_set
completed_project_ids
=
jids_and_ids
.
values_at
(
*
completed_jids
)
if
completed_jids
.
any?
completed_jids_count
+=
completed_jids
.
count
group
.
each
do
|
project
|
project
.
mark_import_as_failed
(
error_message
)
if
completed_jids
.
include?
(
project
.
import_jid
)
end
# We select the projects again, because they may have transitioned from
# scheduled/started to finished/failed while we were looking up their Sidekiq status.
completed_projects
=
enqueued_projects_with_jid
.
where
(
id:
completed_project_ids
)
Rails
.
logger
.
info
(
"Marked stuck import jobs as failed. JIDs:
#{
completed_jids
.
to_a
.
join
(
', '
)
}
"
)
end
end
Rails
.
logger
.
info
(
"Marked stuck import jobs as failed. JIDs:
#{
completed_projects
.
map
(
&
:import_jid
).
join
(
', '
)
}
"
)
completed_jids_count
completed_projects
.
each
do
|
project
|
project
.
mark_import_as_failed
(
error_message
)
end
.
count
end
def
enqueued_projects
...
...
changelogs/unreleased/dm-stuck-import-jobs-verify.yml
0 → 100644
View file @
43a359ab
---
title
:
Verify project import status again before marking as failed
merge_request
:
author
:
type
:
fixed
spec/workers/stuck_import_jobs_worker_spec.rb
View file @
43a359ab
...
...
@@ -2,32 +2,46 @@ require 'spec_helper'
describe
StuckImportJobsWorker
do
let
(
:worker
)
{
described_class
.
new
}
let
(
:exclusive_lease_uuid
)
{
SecureRandom
.
uuid
}
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
exclusive_lease_uuid
)
end
shared_examples
'project import job detection'
do
describe
'long running import'
do
it
'marks the project as failed'
do
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:completed_jids
).
and_return
([
'123'
])
context
'when the job has completed'
do
context
'when the import status was already updated'
do
before
do
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:completed_jids
)
do
project
.
import_start
project
.
import_finish
[
project
.
import_jid
]
end
end
expect
{
worker
.
perform
}.
to
change
{
project
.
reload
.
import_status
}.
to
(
'failed'
)
it
'does not mark the project as failed'
do
worker
.
perform
expect
(
project
.
reload
.
import_status
).
to
eq
(
'finished'
)
end
end
context
'when the import status was not updated'
do
before
do
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:completed_jids
).
and_return
([
project
.
import_jid
])
end
it
'marks the project as failed'
do
worker
.
perform
expect
(
project
.
reload
.
import_status
).
to
eq
(
'failed'
)
end
end
end
describe
'running import
'
do
it
'does not mark the project as failed'
do
context
'when the job is still in Sidekiq
'
do
before
do
allow
(
Gitlab
::
SidekiqStatus
).
to
receive
(
:completed_jids
).
and_return
([])
expect
{
worker
.
perform
}.
not_to
change
{
project
.
reload
.
import_status
}
end
describe
'import without import_jid'
do
it
'marks the project as failed'
do
expect
{
worker
.
perform
}.
to
change
{
project
.
reload
.
import_status
}.
to
(
'failed'
)
end
it
'does not mark the project as failed'
do
expect
{
worker
.
perform
}.
not_to
change
{
project
.
reload
.
import_status
}
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