Commit 8d228998 authored by Furkan Ayhan's avatar Furkan Ayhan

Fix pages build locking problem

atomic processing changes the lock_version of jobs, so it can cause
StaleObjectError in some places
parent ff0a219a
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Projects module Projects
class UpdatePagesService < BaseService class UpdatePagesService < BaseService
include Gitlab::OptimisticLocking
InvalidStateError = Class.new(StandardError) InvalidStateError = Class.new(StandardError)
FailedToExtractError = Class.new(StandardError) FailedToExtractError = Class.new(StandardError)
...@@ -23,8 +25,8 @@ module Projects ...@@ -23,8 +25,8 @@ module Projects
# Create status notifying the deployment of pages # Create status notifying the deployment of pages
@status = create_status @status = create_status
@status.enqueue! retry_optimistic_lock(@status, &:enqueue!)
@status.run! retry_optimistic_lock(@status, &:run!)
raise InvalidStateError, 'missing pages artifacts' unless build.artifacts? raise InvalidStateError, 'missing pages artifacts' unless build.artifacts?
raise InvalidStateError, 'build SHA is outdated for this ref' unless latest? raise InvalidStateError, 'build SHA is outdated for this ref' unless latest?
...@@ -51,7 +53,7 @@ module Projects ...@@ -51,7 +53,7 @@ module Projects
private private
def success def success
@status.success retry_optimistic_lock(@status, &:success)
@project.mark_pages_as_deployed @project.mark_pages_as_deployed
super super
end end
...@@ -61,7 +63,7 @@ module Projects ...@@ -61,7 +63,7 @@ module Projects
log_error("Projects::UpdatePagesService: #{message}") log_error("Projects::UpdatePagesService: #{message}")
@status.allow_failure = !latest? @status.allow_failure = !latest?
@status.description = message @status.description = message
@status.drop(:script_failure) retry_optimistic_lock(@status) { |status| status.drop(:script_failure) }
super super
end end
......
...@@ -106,7 +106,7 @@ module API ...@@ -106,7 +106,7 @@ module API
status.enqueue! status.enqueue!
when 'running' when 'running'
status.enqueue status.enqueue
status.run! Gitlab::OptimisticLocking.retry_lock(status, &:run!)
when 'success' when 'success'
status.success! status.success!
when 'failed' when 'failed'
......
...@@ -158,6 +158,23 @@ describe Projects::UpdatePagesService do ...@@ -158,6 +158,23 @@ describe Projects::UpdatePagesService do
expect(project.pages_metadatum).not_to be_deployed expect(project.pages_metadatum).not_to be_deployed
end end
end end
context 'with background jobs running', :sidekiq_inline do
where(:ci_atomic_processing) do
[true, false]
end
with_them do
before do
stub_feature_flags(ci_atomic_processing: ci_atomic_processing)
end
it 'succeeds' do
expect(project.pages_deployed?).to be_falsey
expect(execute).to eq(:success)
end
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment