Skip to content

Commit 160d9c2

Browse files
committed
feat(commands): management commands to run different polling tasks
1 parent 39f6210 commit 160d9c2

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logging
2+
3+
from django.core.management.base import BaseCommand
4+
5+
from alert_system.models import Connector
6+
from alert_system.tasks import process_connector_task
7+
8+
logger = logging.getLogger(__name__)
9+
10+
11+
class BasePollingCommand(BaseCommand):
12+
help = "Command to extract data from eoapi"
13+
14+
SOURCE_TYPE = None
15+
16+
def handle(self, *args, **options):
17+
if not self.SOURCE_TYPE:
18+
raise ValueError("SOURCE_TYPE must be defined in subclass.")
19+
self.stdout.write("Starting extraction task...")
20+
connector = Connector.objects.filter(type=self.SOURCE_TYPE).first()
21+
if not connector:
22+
logger.warning("No connectors found.")
23+
return
24+
25+
process_connector_task.delay(connector.id)
26+
27+
logger.info("Connector task dispatched.")
28+
29+
self.stdout.write("Extraction task finished.")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from poll_base import BasePollingCommand
2+
from sentry_sdk.crons import monitor
3+
4+
from main.sentry import SentryMonitor
5+
6+
7+
class Command(BasePollingCommand):
8+
help = "Poll data for gdacs cyclone"
9+
SOURCE_TYPE = "GDACS_CYCLONE"
10+
11+
@monitor(monitor_slug=SentryMonitor.POLL_GDACS_CY)
12+
def handle(self, *args, **options):
13+
super().handle(*args, **options)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from sentry_sdk.crons import monitor
2+
3+
from main.sentry import SentryMonitor
4+
5+
from .poll_base import BasePollingCommand
6+
7+
8+
class Command(BasePollingCommand):
9+
help = "Poll data for gdacs flood"
10+
SOURCE_TYPE = "GDACS_FLOOD"
11+
12+
@monitor(monitor_slug=SentryMonitor.POLL_GDACS_FL)
13+
def handle(self, *args, **options):
14+
super().handle(*args, **options)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from sentry_sdk.crons import monitor
2+
3+
from main.sentry import SentryMonitor
4+
5+
from .poll_base import BasePollingCommand
6+
7+
8+
class Command(BasePollingCommand):
9+
help = "Poll data for usgs eartquake"
10+
SOURCE_TYPE = "USGS_EARTHQUAKE"
11+
12+
@monitor(monitor_slug=SentryMonitor.POLL_USGS_EQ)
13+
def handle(self, *args, **options):
14+
super().handle(*args, **options)

0 commit comments

Comments
 (0)