mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
Start work on Royalnet Monitors
This commit is contained in:
parent
7f023ff60b
commit
351540e62c
4 changed files with 33 additions and 1 deletions
|
@ -22,3 +22,4 @@ sentry-sdk>=0.11.1
|
|||
click>=7.0
|
||||
keyring>=19.2.0
|
||||
urllib3>=1.25.6
|
||||
feedparser>=5.2.1
|
||||
|
|
0
royalnet/monitors/__init__.py
Normal file
0
royalnet/monitors/__init__.py
Normal file
30
royalnet/monitors/monitor.py
Normal file
30
royalnet/monitors/monitor.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import asyncio
|
||||
import time
|
||||
|
||||
|
||||
class Monitor:
|
||||
def __init__(self, interval: float, *, loop: asyncio.AbstractEventLoop):
|
||||
self.interval: float = interval
|
||||
self._loop: asyncio.AbstractEventLoop = loop
|
||||
self.last_check_start: float = 0.0
|
||||
self.last_check_end: float = 0.0
|
||||
|
||||
@property
|
||||
def last_check_duration(self):
|
||||
return self.last_check_end - self.last_check_start
|
||||
|
||||
def run_blocking(self):
|
||||
self._loop.run_until_complete(self.run())
|
||||
|
||||
async def run(self):
|
||||
while True:
|
||||
self.last_check_start = time.time()
|
||||
await self.check()
|
||||
self.last_check_end = time.time()
|
||||
await asyncio.sleep(self.interval - self.last_check_duration, loop=self._loop)
|
||||
|
||||
async def check(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def __repr__(self):
|
||||
return f"<{self.__class__.__qualname__} running every {self.interval} seconds>"
|
3
setup.py
3
setup.py
|
@ -32,7 +32,8 @@ setuptools.setup(
|
|||
"sortedcontainers>=2.1.0",
|
||||
"sentry-sdk>=0.11.1",
|
||||
"click>=7.0",
|
||||
"keyring>=19.2.0"],
|
||||
"keyring>=19.2.0",
|
||||
"feedparser>=5.2.1"],
|
||||
python_requires=">=3.7",
|
||||
classifiers=[
|
||||
"Development Status :: 3 - Alpha",
|
||||
|
|
Loading…
Reference in a new issue