-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract common logic into `Operation` from subclasses, so they can focus on the unique behaviour for each respective operation.
- Loading branch information
Showing
5 changed files
with
55 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,21 @@ | ||
module DiscoveryEngine::Sync | ||
class Delete < Operation | ||
def call | ||
lock.acquire | ||
|
||
unless version_cache.sync_required? | ||
super do | ||
client.delete_document(name: document_name) | ||
rescue Google::Cloud::NotFoundError => e | ||
increment_counter("already_not_present") | ||
log( | ||
Logger::Severity::INFO, | ||
"Ignored as newer version already synced", | ||
) | ||
Metrics::Exported.increment_counter( | ||
:discovery_engine_requests, type: "delete", status: "ignored_outdated" | ||
"Did not delete document as it doesn't exist remotely (#{e.message}).", | ||
) | ||
return | ||
end | ||
end | ||
|
||
client.delete_document(name: document_name) | ||
|
||
version_cache.set_as_latest_synced_version | ||
private | ||
|
||
log(Logger::Severity::INFO, "Successfully deleted") | ||
Metrics::Exported.increment_counter( | ||
:discovery_engine_requests, type: "delete", status: "success" | ||
) | ||
rescue Google::Cloud::NotFoundError => e | ||
log( | ||
Logger::Severity::INFO, | ||
"Did not delete document as it doesn't exist remotely (#{e.message}).", | ||
) | ||
Metrics::Exported.increment_counter( | ||
:discovery_engine_requests, type: "delete", status: "already_not_present" | ||
) | ||
rescue Google::Cloud::Error => e | ||
log( | ||
Logger::Severity::ERROR, | ||
"Failed to delete document due to an error (#{e.message})", | ||
) | ||
GovukError.notify(e) | ||
Metrics::Exported.increment_counter( | ||
:discovery_engine_requests, type: "delete", status: "error" | ||
) | ||
ensure | ||
lock.release | ||
def type | ||
:delete | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters