New updates on DB and JSON
This commit is contained in:
@@ -408,6 +408,23 @@ def list_inbox() -> InboxOut:
|
||||
return InboxOut(pending_count=pending_count, submissions=submissions)
|
||||
|
||||
|
||||
def _stamp_origins(manifest, origins: List[str]) -> None:
|
||||
"""Record which drop each file in a freshly staged run came from.
|
||||
|
||||
Done after staging, by position, for the same reason `stage_and_queue`
|
||||
back-fills `rows_total` that way: the staging helpers take a
|
||||
(filename, bytes, rows) tuple shared with the uploads router, and widening
|
||||
it here would change a signature three callers depend on.
|
||||
|
||||
Safe by position because `from-inbox` stages with `invalid=[]`, so
|
||||
manifest.files is exactly `picked` in order.
|
||||
"""
|
||||
for entry, drop_id in zip(manifest.files, origins):
|
||||
entry.from_drop = drop_id
|
||||
batch_ingest.write_manifest(manifest)
|
||||
batch_job_store.put(manifest)
|
||||
|
||||
|
||||
@router.post("/from-inbox", status_code=status.HTTP_202_ACCEPTED,
|
||||
dependencies=[Depends(require_admin)])
|
||||
def start_batch_from_inbox(request: InboxStartRequest) -> BatchOut:
|
||||
@@ -438,6 +455,11 @@ def start_batch_from_inbox(request: InboxStartRequest) -> BatchOut:
|
||||
# what parse_all returns, so nothing needs reparsing here.
|
||||
picked: List[tuple] = []
|
||||
senders: List[str] = []
|
||||
# The drop each picked file came out of, in the SAME ORDER as `picked`, so
|
||||
# it can be stamped onto the staged manifest below. Kept parallel rather
|
||||
# than folded into the tuple because that tuple shape is shared with
|
||||
# parse_all and with the uploads router.
|
||||
origins: List[str] = []
|
||||
for batch_id, indices in grouped.items():
|
||||
manifest = batch_ingest.read_manifest(batch_id)
|
||||
if not manifest or manifest.status != batch_ingest.PENDING:
|
||||
@@ -454,6 +476,7 @@ def start_batch_from_inbox(request: InboxStartRequest) -> BatchOut:
|
||||
# will show it has left the inbox.
|
||||
continue
|
||||
picked.append((entry.filename, contents, entry.rows_total))
|
||||
origins.append(batch_id)
|
||||
if manifest.submitted_by:
|
||||
senders.append(manifest.submitted_by)
|
||||
|
||||
@@ -483,6 +506,7 @@ def start_batch_from_inbox(request: InboxStartRequest) -> BatchOut:
|
||||
fetch_images=request.fetch_images,
|
||||
submitted_by=submitted_by,
|
||||
)
|
||||
_stamp_origins(manifest, origins)
|
||||
else:
|
||||
manifest, started = batch_common.stage_and_queue(
|
||||
picked,
|
||||
@@ -491,6 +515,7 @@ def start_batch_from_inbox(request: InboxStartRequest) -> BatchOut:
|
||||
fetch_images=request.fetch_images,
|
||||
submitted_by=submitted_by,
|
||||
)
|
||||
_stamp_origins(manifest, origins)
|
||||
if not started:
|
||||
raise HTTPException(
|
||||
status_code=429,
|
||||
|
||||
Reference in New Issue
Block a user