Check for station that doesn't return results
parent
7e40d21bbc
commit
26165a8413
|
@ -10,6 +10,7 @@ from orbit import satellite
|
|||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.cache import cache
|
||||
from django.core.mail import send_mail
|
||||
from django.utils.timezone import now
|
||||
|
||||
from network.base.models import Satellite, Tle, Mode, Transmitter, Observation, Station, DemodData
|
||||
|
@ -185,6 +186,34 @@ def station_status_update():
|
|||
station.save()
|
||||
|
||||
|
||||
@app.task(ignore_result=True)
|
||||
def notify_for_stations_without_results():
|
||||
"""Task to send email for stations with observations without results."""
|
||||
email_to = settings.EMAIL_FOR_STATIONS_ISSUES
|
||||
if email_to is not None and len(email_to) > 0:
|
||||
stations = ''
|
||||
obs_limit = settings.OBS_NO_RESULTS_MIN_COUNT
|
||||
time_limit = now() - timedelta(seconds=settings.OBS_NO_RESULTS_IGNORE_TIME)
|
||||
last_check = time_limit - timedelta(seconds=settings.OBS_NO_RESULTS_CHECK_PERIOD)
|
||||
for station in Station.objects.filter(status=2):
|
||||
last_obs = Observation.objects.filter(ground_station=station,
|
||||
end__lt=time_limit).order_by("-end")[:obs_limit]
|
||||
obs_without_results = 0
|
||||
obs_after_last_check = False
|
||||
for observation in last_obs:
|
||||
if not (observation.has_audio and observation.has_waterfall):
|
||||
obs_without_results += 1
|
||||
if observation.end >= last_check:
|
||||
obs_after_last_check = True
|
||||
if obs_without_results == obs_limit and obs_after_last_check:
|
||||
stations += ' ' + str(station.id)
|
||||
if len(stations) > 0:
|
||||
# Notify user
|
||||
subject = '[satnogs] Station with observations without results'
|
||||
send_mail(subject, stations, settings.DEFAULT_FROM_EMAIL,
|
||||
[settings.EMAIL_FOR_STATIONS_ISSUES], False)
|
||||
|
||||
|
||||
@app.task(ignore_result=True)
|
||||
def stations_cache_rates():
|
||||
stations = Station.objects.all()
|
||||
|
|
|
@ -25,7 +25,7 @@ app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
|||
def setup_periodic_tasks(sender, **kwargs):
|
||||
from network.base.tasks import (update_all_tle, fetch_data, clean_observations,
|
||||
station_status_update, stations_cache_rates,
|
||||
sync_to_db)
|
||||
notify_for_stations_without_results, sync_to_db)
|
||||
|
||||
sender.add_periodic_task(RUN_EVERY_TWO_HOURS, update_all_tle.s(),
|
||||
name='update-all-tle')
|
||||
|
@ -42,5 +42,9 @@ def setup_periodic_tasks(sender, **kwargs):
|
|||
sender.add_periodic_task(RUN_HOURLY, stations_cache_rates.s(),
|
||||
name='stations-cache-rates')
|
||||
|
||||
sender.add_periodic_task(settings.OBS_NO_RESULTS_CHECK_PERIOD,
|
||||
notify_for_stations_without_results.s(),
|
||||
name='notify_for_stations_without_results')
|
||||
|
||||
sender.add_periodic_task(RUN_TWICE_HOURLY, sync_to_db.s(),
|
||||
name='sync-to-db')
|
||||
|
|
|
@ -70,6 +70,7 @@ EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)
|
|||
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
|
||||
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
|
||||
DEFAULT_FROM_EMAIL = config('DEFAULT_FROM_EMAIL', default='noreply@satnogs.org')
|
||||
EMAIL_FOR_STATIONS_ISSUES = config('EMAIL_FOR_STATIONS_ISSUES', default='')
|
||||
ADMINS = [
|
||||
('SatNOGS Admins', DEFAULT_FROM_EMAIL)
|
||||
]
|
||||
|
@ -339,6 +340,14 @@ STATION_HEARTBEAT_TIME = config('STATION_HEARTBEAT_TIME', default=60, cast=int)
|
|||
STATION_UPCOMING_END = config('STATION_UPCOMING_END', default=24, cast=int)
|
||||
WIKI_STATION_URL = config('WIKI_STATION_URL', default='https://wiki.satnogs.org/')
|
||||
|
||||
# Station status check
|
||||
# How often, in seconds, will the check for observations with no results runs
|
||||
OBS_NO_RESULTS_CHECK_PERIOD = config('OBS_NO_RESULTS_CHECK_PERIOD', default=21600, cast=int)
|
||||
# Minimum of observations to check for not returning results for each station
|
||||
OBS_NO_RESULTS_MIN_COUNT = config('OBS_NO_RESULTS_MIN_COUNT', default=3, cast=int)
|
||||
# How long, in seconds, from the end of an observation without results, check ignores it.
|
||||
OBS_NO_RESULTS_IGNORE_TIME = config('OBS_NO_RESULTS_IGNORE_TIME', default=1800, cast=int)
|
||||
|
||||
# DB API
|
||||
DB_API_ENDPOINT = config('DB_API_ENDPOINT', default='https://db.satnogs.org/api/')
|
||||
|
||||
|
|
Loading…
Reference in New Issue