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
Show 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
...
@@ -74,8 +74,7 @@ class RemoteMirror < ActiveRecord::Base
end
end
def
sync
def
sync
return
unless
project
return
unless
project
&&
enabled
return
if
!
enabled
||
update_in_progress?
schedule_update_job
schedule_update_job
end
end
...
...
app/workers/repository_update_remote_mirror_worker.rb
View file @
be0f6c42
class
RepositoryUpdateRemoteMirrorWorker
class
RepositoryUpdateRemoteMirrorWorker
UpdateRemoteMirrorError
=
Class
.
new
(
StandardError
)
UpdateAlreadyInProgressError
=
Class
.
new
(
StandardError
)
UpdateError
=
Class
.
new
(
StandardError
)
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
sidekiq_options
queue: :project_mirror
,
retry:
3
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'
]
}
"
Sidekiq
.
logger
.
warn
"Failed
#{
msg
[
'class'
]
}
with
#{
msg
[
'args'
]
}
:
#{
msg
[
'error_message'
]
}
"
end
end
def
perform
(
remote_mirror_id
,
scheduled_time
)
def
perform
(
remote_mirror_id
,
scheduled_time
)
begin
remote_mirror
=
RemoteMirror
.
find
(
remote_mirror_id
)
remote_mirror
=
RemoteMirror
.
find
(
remote_mirror_id
)
return
if
remote_mirror
.
updated_since?
(
scheduled_time
)
return
if
remote_mirror
.
updated_since?
(
scheduled_time
)
raise
UpdateAlreadyInProgressError
if
remote_mirror
.
update_in_progress?
remote_mirror
.
update_start
remote_mirror
.
update_start
project
=
remote_mirror
.
project
project
=
remote_mirror
.
project
current_user
=
project
.
creator
current_user
=
project
.
creator
result
=
Projects
::
UpdateRemoteMirrorService
.
new
(
project
,
current_user
).
execute
(
remote_mirror
)
result
=
Projects
::
UpdateRemoteMirrorService
.
new
(
project
,
current_user
).
execute
(
remote_mirror
)
raise
UpdateRemoteMirrorError
,
result
[
:message
]
if
result
[
:status
]
==
:error
raise
UpdateError
,
result
[
:message
]
if
result
[
:status
]
==
:error
remote_mirror
.
update_finish
remote_mirror
.
update_finish
rescue
UpdateRemoteMirrorError
=>
ex
rescue
UpdateAlreadyInProgressError
raise
rescue
UpdateError
=>
ex
remote_mirror
.
mark_as_failed
(
Gitlab
::
UrlSanitizer
.
sanitize
(
ex
.
message
))
remote_mirror
.
mark_as_failed
(
Gitlab
::
UrlSanitizer
.
sanitize
(
ex
.
message
))
raise
raise
rescue
=>
ex
rescue
=>
ex
raise
UpdateRemoteMirrorError
,
"
#{
ex
.
class
}
:
#{
ex
.
message
}
"
raise
UpdateError
,
"
#{
ex
.
class
}
:
#{
ex
.
message
}
"
end
end
end
end
end
spec/services/git_push_service_spec.rb
View file @
be0f6c42
...
@@ -21,10 +21,11 @@ describe GitPushService, services: true do
...
@@ -21,10 +21,11 @@ describe GitPushService, services: true do
let
(
:ref
)
{
@ref
}
let
(
:ref
)
{
@ref
}
subject
do
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
end
it
'fails stuck remote mirrors'
do
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!
)
expect
(
project
).
to
receive
(
:mark_stuck_remote_mirrors_as_failed!
)
subject
.
execute
subject
.
execute
...
...
spec/workers/repository_update_remote_mirror_worker_spec.rb
View file @
be0f6c42
...
@@ -11,7 +11,7 @@ describe RepositoryUpdateRemoteMirrorWorker do
...
@@ -11,7 +11,7 @@ describe RepositoryUpdateRemoteMirrorWorker do
end
end
describe
'#perform'
do
describe
'#perform'
do
context
'with status
scheduling
'
do
context
'with status
none
'
do
before
do
before
do
remote_mirror
.
update_attributes
(
update_status:
'none'
)
remote_mirror
.
update_attributes
(
update_status:
'none'
)
end
end
...
@@ -23,11 +23,13 @@ describe RepositoryUpdateRemoteMirrorWorker do
...
@@ -23,11 +23,13 @@ describe RepositoryUpdateRemoteMirrorWorker do
end
end
it
'sets status as failed when update remote mirror service executes with errors'
do
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
expect
do
subject
.
perform
(
remote_mirror
.
id
,
Time
.
now
)
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'
)
expect
(
remote_mirror
.
reload
.
update_status
).
to
eq
(
'failed'
)
end
end
...
@@ -41,6 +43,18 @@ describe RepositoryUpdateRemoteMirrorWorker do
...
@@ -41,6 +43,18 @@ describe RepositoryUpdateRemoteMirrorWorker do
end
end
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
context
'with status failed'
do
before
do
before
do
remote_mirror
.
update_attributes
(
update_status:
'failed'
)
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