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

Commit 55a8b5f

Browse files
committed
Make sure we lock the instance prior to updates
1 parent daac37f commit 55a8b5f

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

app/jobs/v3/service_instance_async_job.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ def restart_on_failure?
9898
def execute_request(client)
9999
broker_response = send_broker_request(client)
100100

101-
service_instance.save_with_new_operation(
102-
broker_response[:instance] || {},
103-
broker_response[:last_operation] || {}
104-
)
101+
ManagedServiceInstance.db.transaction do
102+
service_instance.lock!
103+
service_instance.last_operation.lock! if service_instance.last_operation
104+
service_instance.save_with_new_operation(
105+
broker_response[:instance] || {},
106+
broker_response[:last_operation] || {}
107+
)
108+
end
105109
end
106110

107111
def raise_if_cannot_proceed!
@@ -176,11 +180,15 @@ def operation_succeeded
176180

177181
def fail_last_operation(msg)
178182
unless service_instance.blank?
179-
service_instance.save_with_new_operation({}, {
180-
type: operation_type,
181-
state: 'failed',
182-
description: msg,
183-
})
183+
ManagedServiceInstance.db.transaction do
184+
service_instance.last_operation.lock! if service_instance.last_operation
185+
186+
service_instance.save_with_new_operation({}, {
187+
type: operation_type,
188+
state: 'failed',
189+
description: msg,
190+
})
191+
end
184192
end
185193
end
186194

0 commit comments

Comments
 (0)