Break apart create/start logic

This commit is contained in:
Brandon Rising
2023-08-15 16:28:47 -04:00
parent 6cb90e01de
commit 15e7ca1baa
3 changed files with 47 additions and 5 deletions

View File

@ -126,6 +126,14 @@ class BatchProcessStorageBase(ABC):
"""Gets a Batch Process record."""
pass
@abstractmethod
def start(
self,
batch_id: str,
):
"""Start Batch Process record."""
pass
@abstractmethod
def cancel(
self,
@ -360,6 +368,27 @@ class SqliteBatchProcessStorage(BatchProcessStorageBase):
raise BatchProcessNotFoundException
return self._deserialize_batch_process(dict(result))
def start(
self,
batch_id: str,
):
try:
self._lock.acquire()
self._cursor.execute(
f"""--sql
UPDATE batch_process
SET canceled = 0
WHERE batch_id = ?;
""",
(batch_id,),
)
self._conn.commit()
except sqlite3.Error as e:
self._conn.rollback()
raise BatchSessionSaveException from e
finally:
self._lock.release()
def cancel(
self,
batch_id: str,