Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jonathan/appeals 24987 #19003

Merged
merged 12 commits into from
Jul 14, 2023
42 changes: 23 additions & 19 deletions app/models/end_product_establishment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,31 @@ def cancel_unused_end_product!
end

def sync!
# There is no need to sync end_product_status if the status
# is already inactive since an EP can never leave that state
return true unless status_active?

fail EstablishedEndProductNotFound, id unless result

# load contentions now, in case "source" needs them.
# this VBMS call is slow and will cause the transaction below
# to timeout in some cases.
contentions unless result.status_type_code == EndProduct::STATUSES.key("Canceled")
RedisMutex.with_lock("EndProductEstablishment:#{id}", block: 60, expire: 100) do # key => "EndProductEstablishment:id"
# There is no need to sync end_product_status if the status
# is already inactive since an EP can never leave that state
return true unless status_active?

fail EstablishedEndProductNotFound, id unless result

# load contentions now, in case "source" needs them.
# this VBMS call is slow and will cause the transaction below
# to timeout in some cases.
contentions unless result.status_type_code == EndProduct::STATUSES.key("Canceled")

transaction do
update!(
synced_status: result.status_type_code,
last_synced_at: Time.zone.now
)
status_cancelled? ? handle_cancelled_ep! : sync_source!
close_request_issues_with_no_decision!
end

transaction do
update!(
synced_status: result.status_type_code,
last_synced_at: Time.zone.now
)
status_cancelled? ? handle_cancelled_ep! : sync_source!
close_request_issues_with_no_decision!
save_updated_end_product_code!
end

save_updated_end_product_code!
rescue RedisMutex::LockError
Rails.logger.error('failed to acquire lock! EPE sync is being called by another process. Please try again later.')
rescue EstablishedEndProductNotFound, AppealRepository::AppealNotValidToReopen => error
raise error
rescue StandardError => error
Expand Down
Loading