refactored

This commit is contained in:
Robert 2024-02-28 18:41:32 +07:00
parent 674c22afad
commit 271461799d
No known key found for this signature in database
GPG Key ID: F631C7FD957D5F22
5 changed files with 51 additions and 14 deletions

View File

@ -1,9 +1,19 @@
from chain_service.database.models.progress_chain import (
ProgressChain,
BaseProgressAction,
)
from abc import ABC, abstractmethod
from chain_service.database.models.progress_chain import BaseProgressAction
class BaseProgressActionService(ABC):
def __init__(
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
):
self.progress_chain = progress_chain
self.progress_action = progress_action
@abstractmethod
async def process(self, progress_action: BaseProgressAction):
async def process():
pass

View File

@ -1,8 +1,23 @@
from .base import BaseProgressActionService
from chain_service.database.models.progress_chain import CommentProgressAction
from chain_service.database.models.progress_chain import (
BaseProgressAction,
ProgressChain,
)
from planfix_client import PlanfixClient
class CommentProgressActionService(BaseProgressActionService):
async def process(self, progress_action: CommentProgressAction):
print("Comment service", progress_action)
def __init__(
self,
planfix_client: PlanfixClient,
progress_chain: ProgressChain,
progress_action: BaseProgressAction,
):
self.planfix_client = planfix_client
super().__init__(progress_chain, progress_action)
async def process(self):
print("Comment service", self.progress_action, self.planfix_client)

View File

@ -1,4 +1,7 @@
from chain_service.database.models.progress_chain import BaseProgressAction
from chain_service.database.models.progress_chain import (
ProgressChain,
BaseProgressAction,
)
from .base import BaseProgressActionService
from .wait_progress_action import WaitProgressActionService
@ -13,13 +16,19 @@ class ProgressActionServiceFactory:
self.planfix_client = planfix_client
def __call__(
self, progress_action: BaseProgressAction
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
) -> BaseProgressActionService:
match progress_action.action_type:
case "wait":
return WaitProgressActionService()
return WaitProgressActionService(
progress_chain=progress_chain, progress_action=progress_action
)
case "comment":
return CommentProgressActionService(planfix_client=self.planfix_client)
return CommentProgressActionService(
planfix_client=self.planfix_client,
progress_chain=progress_chain,
progress_action=progress_action,
)

View File

@ -1,10 +1,13 @@
from .base import BaseProgressActionService
from chain_service.database.models.progress_chain import WaitProgressAction
from chain_service.database.models.progress_chain import (
ProgressChain,
WaitProgressAction,
)
import asyncio
class WaitProgressActionService(BaseProgressActionService):
async def process(self, progress_action: WaitProgressAction):
await asyncio.sleep(progress_action.wait_for)
async def process(self):
await asyncio.sleep(self.progress_action.wait_for)

View File

@ -44,10 +44,10 @@ class ProgressChainRunnerService:
progress_action.started_at = datetime.utcnow()
progress_action_service = self.progress_action_service_factory(
progress_action
progress_chain=progress_chain, progress_action=progress_action
)
await progress_action_service.process(progress_action)
await progress_action_service.process()
progress_action.status = ProgressActionStatusEnum.DONE
return True