fix(bib): a slow zotero container start no longer fails the sync
Some checks failed
CI / lint (push) Successful in 1m33s
CI / notebooks-smoke (push) Successful in 1m58s
Deploy / changes (push) Successful in 26s
CI / test (push) Successful in 5m27s
Infra CI / zotero (push) Successful in 26s
Infra CI / notebooks (push) Successful in 3m17s
Infra CI / docs (push) Successful in 1m37s
Infra CI / api (push) Successful in 1m59s
Infra CI / bcda (push) Successful in 2m59s
Infra CI / llm (push) Successful in 1m16s
Infra CI / mc (push) Successful in 30s
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Successful in 2m3s
Deploy / report (push) Has been cancelled
Deploy / api (push) Has started running
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Deploy / notebooks (push) Has started running
Some checks failed
CI / lint (push) Successful in 1m33s
CI / notebooks-smoke (push) Successful in 1m58s
Deploy / changes (push) Successful in 26s
CI / test (push) Successful in 5m27s
Infra CI / zotero (push) Successful in 26s
Infra CI / notebooks (push) Successful in 3m17s
Infra CI / docs (push) Successful in 1m37s
Infra CI / api (push) Successful in 1m59s
Infra CI / bcda (push) Successful in 2m59s
Infra CI / llm (push) Successful in 1m16s
Infra CI / mc (push) Successful in 30s
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Successful in 2m3s
Deploy / report (push) Has been cancelled
Deploy / api (push) Has started running
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Deploy / notebooks (push) Has started running
docker start zotero (KasmVNC) can take over 30 s; the subprocess timeout raised after the sync had already written everything, so bib-refresh-iom exited 1. One helper now waits up to 3 min and reports rather than raises.
This commit is contained in:
@@ -11,6 +11,23 @@ import typer
|
||||
app = typer.Typer(no_args_is_help=True)
|
||||
|
||||
|
||||
def _zotero_container(action: str) -> None:
|
||||
"""``docker stop|start zotero`` around a Zotero SQLite write. The
|
||||
KasmVNC container can take well over 30 s to start; waiting longer
|
||||
than 3 min is reported, not raised — the container keeps starting,
|
||||
and the sync's work is already done."""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
["docker", action, "zotero"], capture_output=True, check=False, timeout=180
|
||||
)
|
||||
except subprocess.TimeoutExpired:
|
||||
verb = "still starting" if action == "start" else "still stopping"
|
||||
print(f" zotero container {verb} after 180 s", file=sys.stderr)
|
||||
|
||||
|
||||
@app.command()
|
||||
def sync(
|
||||
dry_run: bool = typer.Option(False, "--dry-run", help="Report without applying."),
|
||||
@@ -930,7 +947,6 @@ def sync_zotero(
|
||||
running. By default we stop the 'zotero' compose service for the
|
||||
duration of the sync and start it again afterward.
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
from bib import connect
|
||||
from bib.sync import dedupe_collection as run_dedupe
|
||||
@@ -941,17 +957,9 @@ def sync_zotero(
|
||||
items = store.list_items(tag=tag, item_type=item_type)
|
||||
zotero_db_path = str(path("db.zotero"))
|
||||
|
||||
def _docker(*args: str) -> None:
|
||||
subprocess.run(
|
||||
["docker", *args],
|
||||
capture_output=True,
|
||||
check=False,
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
try:
|
||||
if hold_zotero:
|
||||
_docker("stop", "zotero")
|
||||
_zotero_container("stop")
|
||||
stats = push_to_zotero(items, store=store, zotero_db=zotero_db_path)
|
||||
if dedupe_collection:
|
||||
stats |= run_dedupe(dedupe_collection, store=store)
|
||||
@@ -974,7 +982,7 @@ def sync_zotero(
|
||||
}
|
||||
finally:
|
||||
if hold_zotero:
|
||||
_docker("start", "zotero")
|
||||
_zotero_container("start")
|
||||
|
||||
for k, v in stats.items():
|
||||
typer.echo(f" {k}: {v}")
|
||||
@@ -1017,7 +1025,6 @@ def attach_oig(
|
||||
@app.command(name="refresh-oig")
|
||||
def refresh_oig() -> None:
|
||||
"""One-shot: ingest-oig → attach-oig → sync-zotero (OIG tag)."""
|
||||
import subprocess
|
||||
|
||||
from bib import connect
|
||||
from bib.oig import download_attachments, ingest_all
|
||||
@@ -1036,14 +1043,10 @@ def refresh_oig() -> None:
|
||||
typer.echo("==> sync-zotero")
|
||||
items = store.list_items(tag="agency:oig")
|
||||
try:
|
||||
subprocess.run(
|
||||
["docker", "stop", "zotero"], capture_output=True, check=False, timeout=30
|
||||
)
|
||||
_zotero_container("stop")
|
||||
stats = push_to_zotero(items, store=store)
|
||||
finally:
|
||||
subprocess.run(
|
||||
["docker", "start", "zotero"], capture_output=True, check=False, timeout=30
|
||||
)
|
||||
_zotero_container("start")
|
||||
typer.echo(
|
||||
f" created={stats['created']} skipped={stats['skipped']} "
|
||||
f"attachments={stats['attachments']}"
|
||||
@@ -1070,7 +1073,6 @@ def refresh_iom(
|
||||
|
||||
Zotero is held (stopped) during the sync phase only.
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
from bib import connect
|
||||
from bib.iom import check_future_updates, download_attachments, ingest_all
|
||||
@@ -1104,14 +1106,10 @@ def refresh_iom(
|
||||
typer.echo("==> sync-zotero")
|
||||
items = store.list_items(item_type="manual")
|
||||
try:
|
||||
subprocess.run(
|
||||
["docker", "stop", "zotero"], capture_output=True, check=False, timeout=30
|
||||
)
|
||||
_zotero_container("stop")
|
||||
stats = push_to_zotero(items, store=store)
|
||||
finally:
|
||||
subprocess.run(
|
||||
["docker", "start", "zotero"], capture_output=True, check=False, timeout=30
|
||||
)
|
||||
_zotero_container("start")
|
||||
typer.echo(
|
||||
f" created={stats['created']} skipped={stats['skipped']} "
|
||||
f"attachments={stats['attachments']}"
|
||||
|
||||
@@ -207,3 +207,18 @@ def test_dmepos_resolve_omits_the_title_needle(
|
||||
assert needles == [("CMS-1691-P", ""), ("CMS-1780-P", "")]
|
||||
for call in api.resolve_docket.call_args_list:
|
||||
assert "title_contains" not in call.kwargs
|
||||
|
||||
|
||||
def test_zotero_container_wait_timeout_is_reported_not_raised(monkeypatch, capsys):
|
||||
# The KasmVNC zotero container can take >30 s to start; the sync's
|
||||
# work was done but bib-refresh-iom exited 1 on TimeoutExpired.
|
||||
import subprocess
|
||||
|
||||
from cli.bib import _zotero_container
|
||||
|
||||
def slow(cmd, **kw):
|
||||
raise subprocess.TimeoutExpired(cmd, kw.get("timeout"))
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", slow)
|
||||
_zotero_container("start")
|
||||
assert "still starting" in capsys.readouterr().err
|
||||
|
||||
Reference in New Issue
Block a user