fix(v2): atomically record execution mutations
This commit is contained in:
@@ -17,7 +17,14 @@ from sqlalchemy.ext.asyncio import async_sessionmaker
|
||||
from backup_tool.config import Settings
|
||||
from backup_tool.db.engine import create_engine
|
||||
from backup_tool.db.models import Execution
|
||||
from backup_tool.execution import claim, complete_cancellation, heartbeat, recover_stale, transition
|
||||
from backup_tool.execution import (
|
||||
claim,
|
||||
complete_cancellation,
|
||||
heartbeat,
|
||||
record_event,
|
||||
recover_stale,
|
||||
transition,
|
||||
)
|
||||
|
||||
|
||||
class Worker:
|
||||
@@ -51,7 +58,7 @@ class Worker:
|
||||
await complete_cancellation(db, execution.id, self.owner)
|
||||
return True
|
||||
now = datetime.now(UTC)
|
||||
await db.execute(
|
||||
result = await db.execute(
|
||||
update(Execution)
|
||||
.where(
|
||||
Execution.id == execution.id,
|
||||
@@ -61,6 +68,9 @@ class Worker:
|
||||
)
|
||||
.values(state=transition("preparing", "running"), started_at=now)
|
||||
)
|
||||
if getattr(result, "rowcount", 0) == 1:
|
||||
await db.refresh(execution)
|
||||
await record_event(db, execution)
|
||||
await db.commit()
|
||||
await heartbeat(db, execution.id, self.owner)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user