Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit a41d75e

Browse files
author
Derik Evangelista
authored
v3(route-bindings): fail the create job when a delete starts (cloudfoundry#1943)
[#174748134](https://www.pivotaltracker.com/story/show/174748134)
1 parent a917640 commit a41d75e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

app/jobs/v3/create_binding_async_job.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
module VCAP::CloudController
88
module V3
99
class CreateBindingAsyncJob < Jobs::ReoccurringJob
10+
class OperationCancelled < StandardError; end
11+
1012
class BindingNotFound < CloudController::Errors::ApiError; end
1113

1214
def initialize(type, precursor_guid, parameters:, user_audit_info:, audit_hash:)
@@ -54,6 +56,8 @@ def resource_type
5456
def perform
5557
not_found! unless resource
5658

59+
cancelled! if delete_in_progress?
60+
5761
compute_maximum_duration
5862

5963
if @first_time
@@ -72,6 +76,8 @@ def perform
7276
if polling_status[:retry_after].present?
7377
self.polling_interval_seconds = polling_status[:retry_after]
7478
end
79+
rescue OperationCancelled => e
80+
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', operation_type, e.message)
7581
rescue BindingNotFound => e
7682
raise e
7783
rescue ServiceBindingCreate::BindingNotRetrievable
@@ -107,6 +113,14 @@ def not_found!
107113
raise BindingNotFound.new_from_details('ResourceNotFound', "The binding could not be found: #{@resource_guid}")
108114
end
109115

116+
def delete_in_progress?
117+
resource.operation_in_progress? && resource.last_operation&.type == 'delete'
118+
end
119+
120+
def cancelled!
121+
raise OperationCancelled.new("#{resource.last_operation.type} in progress")
122+
end
123+
110124
def save_failure(error_message)
111125
if resource.reload.last_operation.state != 'failed'
112126
resource.save_with_attributes_and_new_operation(

spec/support/shared_examples/jobs/create_binding_job.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@
158158
end
159159
end
160160
end
161+
162+
context 'when the operation changes' do
163+
before do
164+
binding.save_with_attributes_and_new_operation({}, { type: 'delete', state: 'in progress' })
165+
end
166+
167+
it 'raises an error' do
168+
expect { subject.perform }.to raise_error(
169+
CloudController::Errors::ApiError,
170+
/create could not be completed: delete in progress/
171+
)
172+
173+
binding.reload
174+
expect(binding.last_operation.state).to eq('in progress')
175+
expect(binding.last_operation.type).to eq('delete')
176+
end
177+
end
161178
end
162179

163180
context 'retry interval' do

0 commit comments

Comments
 (0)