-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86173d8
commit f424b71
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.1.8+rev52" | ||
__version__ = "1.2.0+rev53" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import asyncio | ||
import logging | ||
import requests | ||
|
||
|
||
class UptimeTimer: | ||
def __init__(self, interval_seconds: int, uri: str): | ||
""" | ||
Initializes a heartbeat timer per the specified seconds interval | ||
""" | ||
self.interval_seconds = interval_seconds | ||
self.uri = uri | ||
self.task = asyncio.ensure_future(self.heartbeat()) | ||
self.logger = logging.getLogger(__class__.__name__) | ||
|
||
async def ping(self): | ||
""" | ||
Heartbeats to an UptimeRobot/etc. URL | ||
""" | ||
requests.get(self.uri) | ||
self.logger.info("Sending heartbeat") | ||
await asyncio.sleep(self.interval_seconds) | ||
await self.ping() | ||
|
||
def cancel(self): | ||
""" | ||
Cancels the heartbeat timer task. | ||
""" | ||
self.logger.info("Cancelling heartbeat task") | ||
self.task.cancel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters