File tree Expand file tree Collapse file tree 4 files changed +70
-0
lines changed
alert_system/management/commands Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 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." )
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments