1
0
Fork 0

Add task to update Station status

environments/stage/deployments/77
Nikos Roussos 2018-01-09 18:15:36 +02:00
parent bc52139f70
commit 0c4275d990
No known key found for this signature in database
GPG Key ID: BADFF1767BA7C8E1
2 changed files with 19 additions and 2 deletions

View File

@ -11,7 +11,7 @@ from django.conf import settings
from django.contrib.sites.models import Site
from django.utils.timezone import now
from network.base.models import Satellite, Tle, Mode, Transmitter, Observation
from network.base.models import Satellite, Tle, Mode, Transmitter, Observation, Station
from network.celery import app
@ -145,3 +145,16 @@ def clean_observations():
if not obs.is_good:
obs.delete()
archive_audio.delay(obs.id)
@app.task
def station_status_update():
"""Task to update Station status."""
for station in Station.objects.all():
if station.is_offline:
station.status = 0
elif station.testing:
station.status = 1
else:
station.status = 2
station.save()

View File

@ -20,7 +20,8 @@ app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
from network.base.tasks import update_all_tle, fetch_data, clean_observations
from network.base.tasks import (update_all_tle, fetch_data, clean_observations,
station_status_update)
sender.add_periodic_task(RUN_HOURLY, update_all_tle.s(),
name='update-all-tle')
@ -28,6 +29,9 @@ def setup_periodic_tasks(sender, **kwargs):
sender.add_periodic_task(RUN_HOURLY, fetch_data.s(),
name='fetch-data')
sender.add_periodic_task(RUN_HOURLY, station_status_update.s(),
name='station-status-update')
sender.add_periodic_task(RUN_DAILY, clean_observations.s(),
name='clean-observations')