Skip to content

Commit 7031c1e

Browse files
committed
[DOP-25451] Update run status in separated commit
1 parent d1311fd commit 7031c1e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

syncmaster/worker/transfer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def run_transfer_task(self: WorkerTask, run_id: int) -> None:
3333

3434
def run_transfer(run_id: int, engine: Engine, settings: WorkerAppSettings):
3535
try:
36-
with Session(engine) as session:
36+
with Session(engine, expire_on_commit=False) as session:
3737
run = session.scalar(
3838
select(Run)
3939
.where(
@@ -66,8 +66,8 @@ def run_transfer(run_id: int, engine: Engine, settings: WorkerAppSettings):
6666
run=run,
6767
correlation_id=correlation_id.get(),
6868
)
69-
session.add(run)
7069
session.commit()
70+
session.expunge_all() # do not hold open DB connection while run is executed
7171

7272
controller = TransferController(
7373
settings=settings,
@@ -80,7 +80,7 @@ def run_transfer(run_id: int, engine: Engine, settings: WorkerAppSettings):
8080
controller.perform_transfer()
8181
except Exception as e:
8282
status = Status.FAILED
83-
logger.exception("Run %r failed", run_id)
83+
logger.error("Run %r failed", run_id)
8484
exception = e
8585
else:
8686
status = Status.FINISHED
@@ -90,10 +90,9 @@ def run_transfer(run_id: int, engine: Engine, settings: WorkerAppSettings):
9090
with Session(engine) as session:
9191
run = session.get(Run, run_id)
9292
if run:
93-
logger.info("Updating run status")
93+
logger.info("Updating run status in DB")
9494
run.status = status
9595
run.ended_at = datetime.now(tz=timezone.utc)
96-
session.add(run)
9796
session.commit()
9897

9998
if exception is not None:

0 commit comments

Comments
 (0)