missionpanel 1.2.4__tar.gz → 1.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {missionpanel-1.2.4 → missionpanel-1.2.6}/PKG-INFO +1 -1
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/example/__init__.py +1 -0
- missionpanel-1.2.6/missionpanel/example/subprocess.py +34 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/handler/handler.py +14 -4
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel.egg-info/PKG-INFO +1 -1
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel.egg-info/SOURCES.txt +1 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/setup.py +1 -1
- {missionpanel-1.2.4 → missionpanel-1.2.6}/LICENSE +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/README.md +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/__init__.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/example/rsshub.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/example/ttrss.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/handler/__init__.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/orm/__init__.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/orm/core.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/orm/handler.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/submitter/__init__.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/submitter/abc.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/submitter/asynchronous.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel/submitter/submitter.py +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel.egg-info/dependency_links.txt +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel.egg-info/requires.txt +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/missionpanel.egg-info/top_level.txt +0 -0
- {missionpanel-1.2.4 → missionpanel-1.2.6}/setup.cfg +0 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
import abc
|
2
|
+
import asyncio
|
3
|
+
import logging
|
4
|
+
from typing import List, Callable
|
5
|
+
from missionpanel.handler import AsyncHandler
|
6
|
+
from missionpanel.orm.core import Mission
|
7
|
+
from missionpanel.orm.handler import Attempt
|
8
|
+
|
9
|
+
|
10
|
+
class SubprocessAsyncHandler(AsyncHandler, abc.ABC):
|
11
|
+
def getLogger(self) -> logging.Logger:
|
12
|
+
return logging.getLogger("SubprocessAsyncHandler")
|
13
|
+
|
14
|
+
async def __readline_info(self, f):
|
15
|
+
async for line in f:
|
16
|
+
self.getLogger().info(
|
17
|
+
'stdout | %s' % line.strip())
|
18
|
+
|
19
|
+
async def __readline_debug(self, f):
|
20
|
+
async for line in f:
|
21
|
+
self.getLogger().info(
|
22
|
+
'stderr | %s' % line.strip())
|
23
|
+
|
24
|
+
@abc.abstractmethod
|
25
|
+
async def construct_command(self, mission: Mission, attempt: Attempt) -> str:
|
26
|
+
raise NotImplementedError("Subclasses must implement construct_command")
|
27
|
+
|
28
|
+
async def execute_mission(self, mission: Mission, attempt: Attempt) -> bool:
|
29
|
+
proc = await asyncio.create_subprocess_shell(
|
30
|
+
await self.construct_command(mission, attempt),
|
31
|
+
stdout=asyncio.subprocess.PIPE,
|
32
|
+
stderr=asyncio.subprocess.PIPE)
|
33
|
+
await asyncio.gather(self.__readline_info(proc.stdout), self.__readline_debug(proc.stderr))
|
34
|
+
return (await proc.wait()) == 0
|
@@ -96,14 +96,24 @@ class AsyncHandler(HandlerInterface, abc.ABC):
|
|
96
96
|
async def execute_mission(self, mission: Mission, attempt: Attempt) -> bool:
|
97
97
|
pass
|
98
98
|
|
99
|
-
async def
|
99
|
+
async def get_mission(self, tags: List[str]) -> Optional[Mission]:
|
100
100
|
missions = (await self.session.execute(HandlerInterface.query_todo_missions(tags))).scalars().all()
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
return await self.select_mission(missions)
|
102
|
+
|
103
|
+
async def run_mission(self, mission: Mission):
|
104
104
|
attempt = HandlerInterface.create_attempt(self.session, mission, self.name, self.max_time_interval)
|
105
105
|
await self.report_attempt(mission, attempt)
|
106
106
|
if await self.execute_mission(mission, attempt):
|
107
107
|
attempt.success = True
|
108
108
|
await self.report_attempt(mission, attempt)
|
109
109
|
return attempt
|
110
|
+
|
111
|
+
async def run_once(self, tags: List[str]):
|
112
|
+
mission = await self.get_mission(tags)
|
113
|
+
if mission is None:
|
114
|
+
return
|
115
|
+
return await self.run_mission(mission)
|
116
|
+
|
117
|
+
async def run_all(self, tags: List[str]):
|
118
|
+
while await self.run_once(tags):
|
119
|
+
pass
|
@@ -9,6 +9,7 @@ missionpanel.egg-info/requires.txt
|
|
9
9
|
missionpanel.egg-info/top_level.txt
|
10
10
|
missionpanel/example/__init__.py
|
11
11
|
missionpanel/example/rsshub.py
|
12
|
+
missionpanel/example/subprocess.py
|
12
13
|
missionpanel/example/ttrss.py
|
13
14
|
missionpanel/handler/__init__.py
|
14
15
|
missionpanel/handler/handler.py
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|