abort chain logic
This commit is contained in:
parent
adadadb92e
commit
17f5b9d797
|
|
@ -7,6 +7,7 @@ from chain_service.database.models.progress_chain import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from chain_service.repositories.progress_chain import ProgressChainRepository
|
from chain_service.repositories.progress_chain import ProgressChainRepository
|
||||||
|
from chain_service.repositories.running_chain import RunningChainRepository
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
@ -18,9 +19,11 @@ class ProgressChainRunnerService:
|
||||||
self,
|
self,
|
||||||
progress_chain_repository: ProgressChainRepository,
|
progress_chain_repository: ProgressChainRepository,
|
||||||
progress_action_service_factory: ProgressActionServiceFactory,
|
progress_action_service_factory: ProgressActionServiceFactory,
|
||||||
|
running_chain_repository: RunningChainRepository,
|
||||||
):
|
):
|
||||||
self.progress_chain_repository = progress_chain_repository
|
self.progress_chain_repository = progress_chain_repository
|
||||||
self.progress_action_service_factory = progress_action_service_factory
|
self.progress_action_service_factory = progress_action_service_factory
|
||||||
|
self.running_chain_repository = running_chain_repository
|
||||||
|
|
||||||
async def process(self, progress_chain: ProgressChain):
|
async def process(self, progress_chain: ProgressChain):
|
||||||
|
|
||||||
|
|
@ -36,6 +39,8 @@ class ProgressChainRunnerService:
|
||||||
if not await self.process_action(progress_chain, progress_action):
|
if not await self.process_action(progress_chain, progress_action):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
await self.running_chain_repository.delete(progress_chain.chain_id)
|
||||||
|
|
||||||
async def process_action(
|
async def process_action(
|
||||||
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
|
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
|
||||||
):
|
):
|
||||||
|
|
@ -48,9 +53,15 @@ class ProgressChainRunnerService:
|
||||||
)
|
)
|
||||||
|
|
||||||
await progress_action_service.process()
|
await progress_action_service.process()
|
||||||
|
assert await self.running_chain_repository.exists(progress_chain.chain_id)
|
||||||
progress_action.status = ProgressActionStatusEnum.DONE
|
progress_action.status = ProgressActionStatusEnum.DONE
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
except AssertionError:
|
||||||
|
logger.info(f"Chain was aborted {progress_chain.chain_id}")
|
||||||
|
progress_action.status = ProgressActionStatusEnum.ABORTED
|
||||||
|
return False
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.exception(f"Error during action process for {progress_chain.id}")
|
logger.exception(f"Error during action process for {progress_chain.id}")
|
||||||
progress_action.status = ProgressActionStatusEnum.FAILED
|
progress_action.status = ProgressActionStatusEnum.FAILED
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user