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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
be0f6c42
Commit
be0f6c42
authored
May 01, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raises error if another worker is already running and improves code quality
parent
ebf5e945
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
27 deletions
+44
-27
app/models/remote_mirror.rb
app/models/remote_mirror.rb
+1
-2
app/workers/repository_update_remote_mirror_worker.rb
app/workers/repository_update_remote_mirror_worker.rb
+24
-21
spec/services/git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+2
-1
spec/workers/repository_update_remote_mirror_worker_spec.rb
spec/workers/repository_update_remote_mirror_worker_spec.rb
+17
-3
No files found.
app/models/remote_mirror.rb
View file @
be0f6c42
...
...
@@ -74,8 +74,7 @@ class RemoteMirror < ActiveRecord::Base
end
def
sync
return
unless
project
return
if
!
enabled
||
update_in_progress?
return
unless
project
&&
enabled
schedule_update_job
end
...
...
app/workers/repository_update_remote_mirror_worker.rb
View file @
be0f6c42
class
RepositoryUpdateRemoteMirrorWorker
UpdateRemoteMirrorError
=
Class
.
new
(
StandardError
)
UpdateAlreadyInProgressError
=
Class
.
new
(
StandardError
)
UpdateError
=
Class
.
new
(
StandardError
)
include
Sidekiq
::
Worker
include
Gitlab
::
ShellAdapter
sidekiq_options
queue: :project_mirror
,
retry:
3
sidekiq_retries_exhausted
do
|
msg
,
e
|
sidekiq_retry_in
{
|
count
|
30
*
count
}
sidekiq_retries_exhausted
do
|
msg
,
_
|
Sidekiq
.
logger
.
warn
"Failed
#{
msg
[
'class'
]
}
with
#{
msg
[
'args'
]
}
:
#{
msg
[
'error_message'
]
}
"
end
def
perform
(
remote_mirror_id
,
scheduled_time
)
begin
remote_mirror
=
RemoteMirror
.
find
(
remote_mirror_id
)
return
if
remote_mirror
.
updated_since?
(
scheduled_time
)
remote_mirror
.
update_start
project
=
remote_mirror
.
project
current_user
=
project
.
creator
result
=
Projects
::
UpdateRemoteMirrorService
.
new
(
project
,
current_user
).
execute
(
remote_mirror
)
raise
UpdateRemoteMirror
Error
,
result
[
:message
]
if
result
[
:status
]
==
:error
remote_mirror
.
update_finish
r
escue
UpdateRemoteMirrorError
=>
ex
remote_mirror
.
mark_as_failed
(
Gitlab
::
UrlSanitizer
.
sanitize
(
ex
.
message
))
raise
r
escue
=>
ex
raise
UpdateRemoteMirrorError
,
"
#{
ex
.
class
}
:
#{
ex
.
message
}
"
end
remote_mirror
=
RemoteMirror
.
find
(
remote_mirror_id
)
return
if
remote_mirror
.
updated_since?
(
scheduled_time
)
raise
UpdateAlreadyInProgressError
if
remote_mirror
.
update_in_progress?
remote_mirror
.
update_start
project
=
remote_mirror
.
project
current_user
=
project
.
creator
result
=
Projects
::
UpdateRemoteMirrorService
.
new
(
project
,
current_user
).
execute
(
remote_mirror
)
raise
Update
Error
,
result
[
:message
]
if
result
[
:status
]
==
:error
remote_mirror
.
update_finish
rescue
UpdateAlreadyInProgressError
r
aise
rescue
UpdateError
=>
ex
remote_mirror
.
mark_as_failed
(
Gitlab
::
UrlSanitizer
.
sanitize
(
ex
.
message
))
r
aise
rescue
=>
ex
raise
UpdateError
,
"
#{
ex
.
class
}
:
#{
ex
.
message
}
"
end
end
spec/services/git_push_service_spec.rb
View file @
be0f6c42
...
...
@@ -21,10 +21,11 @@ describe GitPushService, services: true do
let
(
:ref
)
{
@ref
}
subject
do
described_class
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
described_class
.
new
(
project
,
user
,
oldrev:
oldrev
,
newrev:
newrev
,
ref:
ref
)
end
it
'fails stuck remote mirrors'
do
allow
(
project
).
to
receive
(
:update_remote_mirrors
).
and_return
(
project
.
remote_mirrors
)
expect
(
project
).
to
receive
(
:mark_stuck_remote_mirrors_as_failed!
)
subject
.
execute
...
...
spec/workers/repository_update_remote_mirror_worker_spec.rb
View file @
be0f6c42
...
...
@@ -11,7 +11,7 @@ describe RepositoryUpdateRemoteMirrorWorker do
end
describe
'#perform'
do
context
'with status
scheduling
'
do
context
'with status
none
'
do
before
do
remote_mirror
.
update_attributes
(
update_status:
'none'
)
end
...
...
@@ -23,11 +23,13 @@ describe RepositoryUpdateRemoteMirrorWorker do
end
it
'sets status as failed when update remote mirror service executes with errors'
do
e
xpect_any_instance_of
(
Projects
::
UpdateRemoteMirrorService
).
to
receive
(
:execute
).
with
(
remote_mirror
).
and_return
(
status: :error
,
message:
'fail!'
)
e
rror_message
=
'fail!'
expect_any_instance_of
(
Projects
::
UpdateRemoteMirrorService
).
to
receive
(
:execute
).
with
(
remote_mirror
).
and_return
(
status: :error
,
message:
error_message
)
expect
do
subject
.
perform
(
remote_mirror
.
id
,
Time
.
now
)
end
.
to
raise_error
end
.
to
raise_error
(
RepositoryUpdateRemoteMirrorWorker
::
UpdateError
,
'fail!'
)
expect
(
remote_mirror
.
reload
.
update_status
).
to
eq
(
'failed'
)
end
...
...
@@ -41,6 +43,18 @@ describe RepositoryUpdateRemoteMirrorWorker do
end
end
context
'with another worker already running'
do
before
do
remote_mirror
.
update_attributes
(
update_status:
'started'
)
end
it
'raises RemoteMirrorUpdateAlreadyInProgressError'
do
expect
do
subject
.
perform
(
remote_mirror
.
id
,
Time
.
now
)
end
.
to
raise_error
(
RepositoryUpdateRemoteMirrorWorker
::
UpdateAlreadyInProgressError
)
end
end
context
'with status failed'
do
before
do
remote_mirror
.
update_attributes
(
update_status:
'failed'
)
...
...
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