Automatically resume empty saved source reviews
This commit is contained in:
1 parent
cd362b3b81
commit
976a4fa7b2
11 files changed
+585
-29
No files matched your search
@@ -3,7 +3,7 @@ from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from arr_web.arr_download_handoff import outcome_from_handoff
|
||||
from arr_web.arr_downloads import DownloadOutcome, validate_request_id
|
||||
from arr_web.arr_downloads import DownloadOutcome, validate_report_date, validate_request_id
|
||||
from integrations.ohip.arr_data import ARRDataSource, VERSION as SOURCE_VERSION
|
||||
from integrations.ohip import processing_handoff as handoff
|
||||
from integrations.ohip.audit_arr_capture import protected_read
|
||||
@@ -34,6 +34,23 @@ class DirectARRExecutor:
|
||||
def finalize_data_review(self, request_id, revision, actor):
|
||||
return self.data_reviews.finalize(request_id, revision, actor)
|
||||
|
||||
def recover_data_review(self, request_id):
|
||||
# Recovery may resume only an already collected, exactly bound local
|
||||
# request. A missing/conflicting checkpoint must not start another fetch.
|
||||
validate_request_id(request_id)
|
||||
directory = self.root / "requests" / request_id
|
||||
stored = strict_json(protected_read(directory / "request.json", 65536))
|
||||
report_date = validate_report_date(stored.get("report_date"))
|
||||
identity = {**self.source_identity(), "request_id": request_id, "report_date": report_date}
|
||||
require(fingerprint(stored) == fingerprint(identity), "data_executor_request_conflict")
|
||||
checkpoint = strict_json(protected_read(directory / "collected.json", 65536))
|
||||
require(fingerprint(checkpoint["identity"]) == fingerprint(identity), "data_collection_checkpoint_conflict")
|
||||
payload, manifest = self.data_reviews.original(request_id)
|
||||
require(handoff._hash(payload) == checkpoint["data_sha256"]
|
||||
and manifest == checkpoint["manifest_sha256"]
|
||||
and strict_json(payload).get("report_date") == report_date, "data_collection_checkpoint_changed")
|
||||
return self.data_reviews.recover_ready(request_id)
|
||||
|
||||
def source_identity(self):
|
||||
return {"version": "arr-direct-data-executor/v1", "source_version": SOURCE_VERSION,
|
||||
"hotel_id": self.source.hotel_id, "service_url": SERVICE, "application_id": APPLICATION,
|
||||
@@ -90,6 +107,7 @@ class DirectARRExecutor:
|
||||
"manifest_sha256": original_manifest}, replace=False)
|
||||
manifest_sha256 = original_manifest
|
||||
if review:
|
||||
self.recover_data_review(request_id)
|
||||
completed = self.data_reviews.payload(request_id)
|
||||
if completed is None:
|
||||
return DownloadOutcome("needs_data_review")
|
||||
|
||||
Reference in new issue
Block a user