refactored
This commit is contained in:
parent
674c22afad
commit
271461799d
|
|
@ -1,9 +1,19 @@
|
||||||
|
from chain_service.database.models.progress_chain import (
|
||||||
|
ProgressChain,
|
||||||
|
BaseProgressAction,
|
||||||
|
)
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from chain_service.database.models.progress_chain import BaseProgressAction
|
|
||||||
|
|
||||||
|
|
||||||
class BaseProgressActionService(ABC):
|
class BaseProgressActionService(ABC):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
|
||||||
|
):
|
||||||
|
self.progress_chain = progress_chain
|
||||||
|
self.progress_action = progress_action
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def process(self, progress_action: BaseProgressAction):
|
async def process():
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,23 @@
|
||||||
from .base import BaseProgressActionService
|
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):
|
class CommentProgressActionService(BaseProgressActionService):
|
||||||
|
|
||||||
async def process(self, progress_action: CommentProgressAction):
|
def __init__(
|
||||||
print("Comment service", progress_action)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -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 .base import BaseProgressActionService
|
||||||
from .wait_progress_action import WaitProgressActionService
|
from .wait_progress_action import WaitProgressActionService
|
||||||
|
|
@ -13,13 +16,19 @@ class ProgressActionServiceFactory:
|
||||||
self.planfix_client = planfix_client
|
self.planfix_client = planfix_client
|
||||||
|
|
||||||
def __call__(
|
def __call__(
|
||||||
self, progress_action: BaseProgressAction
|
self, progress_chain: ProgressChain, progress_action: BaseProgressAction
|
||||||
) -> BaseProgressActionService:
|
) -> BaseProgressActionService:
|
||||||
|
|
||||||
match progress_action.action_type:
|
match progress_action.action_type:
|
||||||
|
|
||||||
case "wait":
|
case "wait":
|
||||||
return WaitProgressActionService()
|
return WaitProgressActionService(
|
||||||
|
progress_chain=progress_chain, progress_action=progress_action
|
||||||
|
)
|
||||||
|
|
||||||
case "comment":
|
case "comment":
|
||||||
return CommentProgressActionService(planfix_client=self.planfix_client)
|
return CommentProgressActionService(
|
||||||
|
planfix_client=self.planfix_client,
|
||||||
|
progress_chain=progress_chain,
|
||||||
|
progress_action=progress_action,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
from .base import BaseProgressActionService
|
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
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
class WaitProgressActionService(BaseProgressActionService):
|
class WaitProgressActionService(BaseProgressActionService):
|
||||||
|
|
||||||
async def process(self, progress_action: WaitProgressAction):
|
async def process(self):
|
||||||
await asyncio.sleep(progress_action.wait_for)
|
await asyncio.sleep(self.progress_action.wait_for)
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,10 @@ class ProgressChainRunnerService:
|
||||||
progress_action.started_at = datetime.utcnow()
|
progress_action.started_at = datetime.utcnow()
|
||||||
|
|
||||||
progress_action_service = self.progress_action_service_factory(
|
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
|
progress_action.status = ProgressActionStatusEnum.DONE
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user