chain-service/chain_service/repositories/running_chain.py
2024-04-02 20:33:59 +07:00

32 lines
1.0 KiB
Python

from chain_service.database.database import Database
class RunningChainRepository:
def __init__(self, database: Database):
self.collection = database.get_collection("running_chains")
async def add(self, task_id: str, progress_chain_id: str):
query = {"taskId": task_id}
payload = {"taskId": task_id, "progressChainId": progress_chain_id}
await self.collection.replace_one(query, payload, upsert=True)
async def exists(self, task_id: str, progress_chain_id: str = None) -> bool:
query = {"taskId": task_id}
if progress_chain_id:
query = {"progressChainId": progress_chain_id}
return bool(await self.collection.find_one(query))
async def delete(self, task_id: str, progress_chain_id: str = None) -> bool:
query = {"taskId": task_id}
if progress_chain_id:
query = {"progressChainId": progress_chain_id}
await self.collection.delete_one(query)
async def delete_all(self):
await self.collection.delete_many({})