Skip to content

Commit 38c47db

Browse files
Allow database override for reinjecting failed API calls (#660)
The database is set to default to the one in the security configuration in parts of the feedback process. To make it easier to use the API call reinjection these should take the database as input instead, and only the overall feedback_callback function should have the default. A similar problem occurs with the machine configuration which will need to be set when using the API reinjection for now. One naming issue is we import the database spec as db into feedback.py then have _db as a session object. This might be confusing.
1 parent 299f31f commit 38c47db

File tree

5 files changed

+128
-112
lines changed

5 files changed

+128
-112
lines changed

src/murfey/cli/repost_failed_calls.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from queue import Empty, Queue
99

10-
from sqlmodel import Session
10+
from sqlmodel import Session, create_engine
1111
from workflows.transport.pika_transport import PikaTransport
1212

1313
import murfey.server.api.auth
@@ -25,7 +25,7 @@
2525
import murfey.server.api.session_info
2626
import murfey.server.api.websocket
2727
import murfey.server.api.workflow
28-
from murfey.server.murfey_db import get_murfey_db_session
28+
from murfey.server.murfey_db import url
2929
from murfey.util.config import security_from_file
3030

3131

@@ -162,7 +162,10 @@ def run():
162162
- feedback messages that can be sent back to rabbitmq
163163
"""
164164
parser = argparse.ArgumentParser(
165-
description="Purge and reinject failed murfey messages"
165+
description=(
166+
"Purge and reinject failed murfey messages. "
167+
"Provide security configuration and set machine configuration."
168+
)
166169
)
167170
parser.add_argument(
168171
"-c",
@@ -177,7 +180,6 @@ def run():
177180

178181
# Read the security config file
179182
security_config = security_from_file(args.config)
180-
murfey_db = get_murfey_db_session(security_config)
181183

182184
# Purge the queue and repost/reinject any messages found
183185
dlq_dump_path = Path(args.dir)
@@ -187,7 +189,14 @@ def run():
187189
security_config.feedback_queue,
188190
security_config.rabbitmq_credentials,
189191
)
190-
handle_failed_posts(exported_messages, murfey_db)
192+
193+
# Set up database and retry api calls
194+
_url = url(security_config)
195+
engine = create_engine(_url)
196+
with Session(engine) as murfey_db:
197+
handle_failed_posts(exported_messages, murfey_db)
198+
199+
# Reinject all remaining messages to rabbitmq
191200
handle_dlq_messages(exported_messages, security_config.rabbitmq_credentials)
192201

193202
# Clean up any created directories

src/murfey/server/api/workflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def register_completed_tilt_series(
768768
db.commit()
769769
for ts in tilt_series_db:
770770
if (
771-
check_tilt_series_mc(ts.id)
771+
check_tilt_series_mc(ts.id, db)
772772
and not ts.processing_requested
773773
and ts.tilt_series_length > 2
774774
):
@@ -795,9 +795,9 @@ def register_completed_tilt_series(
795795
machine_config = get_machine_config(instrument_name=instrument_name)[
796796
instrument_name
797797
]
798-
tilts = get_all_tilts(ts.id)
799-
ids = get_job_ids(ts.id, collected_ids[3].id)
800-
preproc_params = get_tomo_proc_params(ids.dcgid)
798+
tilts = get_all_tilts(ts.id, db)
799+
ids = get_job_ids(ts.id, collected_ids[3].id, db)
800+
preproc_params = get_tomo_proc_params(ids.dcgid, db)
801801

802802
first_tilt = db.exec(
803803
select(Tilt).where(Tilt.tilt_series_id == ts.id)

src/murfey/server/demo_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def register_dc_group(
748748

749749
if dcg_params.atlas:
750750
_flush_grid_square_records(
751-
{"session_id": session_id, "tag": dcg_params.tag}, demo=True
751+
{"session_id": session_id, "tag": dcg_params.tag}, _db=db, demo=True
752752
)
753753
return dcg_params
754754

0 commit comments

Comments
 (0)