2023-08-20 22:53:35 -07:00
|
|
|
from abc import ABC, abstractmethod
|
2023-09-07 12:50:13 +08:00
|
|
|
from .compute_task import ComputeTask, ComputeTaskType
|
2023-08-27 18:07:33 -07:00
|
|
|
|
2023-08-20 22:53:35 -07:00
|
|
|
|
2023-08-23 11:19:16 -07:00
|
|
|
class ComputeNode(ABC):
|
2023-08-27 18:07:33 -07:00
|
|
|
def __init__(self) -> None:
|
|
|
|
|
self.node_id = "default"
|
|
|
|
|
self.enable = True
|
|
|
|
|
|
2023-08-22 17:11:20 -07:00
|
|
|
@abstractmethod
|
2023-09-07 12:50:13 +08:00
|
|
|
async def push_task(self, task: ComputeTask, proiority: int = 0):
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
2023-09-07 12:50:13 +08:00
|
|
|
|
2023-08-27 18:07:33 -07:00
|
|
|
@abstractmethod
|
2023-09-07 12:50:13 +08:00
|
|
|
async def remove_task(self, task_id: str):
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-09-07 12:50:13 +08:00
|
|
|
def get_task_state(self, task_id: str):
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
2023-08-20 22:53:35 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def display(self) -> str:
|
|
|
|
|
pass
|
|
|
|
|
|
2023-08-22 17:11:20 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_capacity(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-09-14 15:22:38 +08:00
|
|
|
def is_support(self, task: ComputeTask) -> bool:
|
2023-08-22 17:11:20 -07:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def is_local(self) -> bool:
|
|
|
|
|
pass
|
|
|
|
|
|
2023-09-18 07:58:08 +00:00
|
|
|
def weight(self) -> int:
|
|
|
|
|
return 1
|
|
|
|
|
|
2023-08-22 17:11:20 -07:00
|
|
|
def is_trusted(self) -> bool:
|
|
|
|
|
return True
|
2023-09-07 12:50:13 +08:00
|
|
|
|
2023-08-22 17:11:20 -07:00
|
|
|
def get_fee_type(self) -> str:
|
|
|
|
|
return "free"
|
2023-09-07 12:50:13 +08:00
|
|
|
|
2023-08-23 11:19:16 -07:00
|
|
|
class LocalComputeNode(ComputeNode):
|
2023-08-20 22:53:35 -07:00
|
|
|
def display(self) -> str:
|
|
|
|
|
return super().display()
|
2023-09-07 12:50:13 +08:00
|
|
|
|
2023-08-22 17:11:20 -07:00
|
|
|
def is_local(self) -> bool:
|
2023-09-14 15:22:38 +08:00
|
|
|
return True
|