mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-02-04 17:24:30 +00:00
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
import pytz
|
|
|
|
from core.config import MAX_ALERT_AGE
|
|
from spothole import add_alert
|
|
|
|
|
|
# Generic alert provider class. Subclasses of this query the individual APIs for alerts.
|
|
class AlertProvider:
|
|
|
|
# Constructor
|
|
def __init__(self, provider_config):
|
|
self.name = provider_config["name"]
|
|
self.enabled = provider_config["enabled"]
|
|
self.last_update_time = datetime.min.replace(tzinfo=pytz.UTC)
|
|
self.status = "Not Started" if self.enabled else "Disabled"
|
|
self.alerts = None
|
|
|
|
# Set up the provider, e.g. giving it the alert list to work from
|
|
def setup(self, alerts):
|
|
self.alerts = alerts
|
|
|
|
# Start the provider. This should return immediately after spawning threads to access the remote resources
|
|
def start(self):
|
|
raise NotImplementedError("Subclasses must implement this method")
|
|
|
|
# Submit a batch of alerts retrieved from the provider. There is no timestamp checking like there is for spots,
|
|
# because alerts could be created at any point for any time in the future. Rely on hashcode-based id matching
|
|
# to deal with duplicates.
|
|
def submit_batch(self, alerts):
|
|
for alert in alerts:
|
|
# Fill in any blanks and add to the list
|
|
alert.infer_missing()
|
|
add_alert(alert)
|
|
|
|
# Stop any threads and prepare for application shutdown
|
|
def stop(self):
|
|
raise NotImplementedError("Subclasses must implement this method") |