2017-09-27 11:04:18 -06:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from celery import Celery
|
2019-09-23 05:08:11 -06:00
|
|
|
from django.conf import settings # noqa
|
2017-09-27 11:04:18 -06:00
|
|
|
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'network.settings')
|
|
|
|
|
|
|
|
RUN_DAILY = 60 * 60 * 24
|
2018-08-24 15:35:19 -06:00
|
|
|
RUN_EVERY_TWO_HOURS = 2 * 60 * 60
|
2017-09-27 11:04:18 -06:00
|
|
|
RUN_HOURLY = 60 * 60
|
2018-09-02 14:05:15 -06:00
|
|
|
RUN_EVERY_MINUTE = 60
|
2019-02-06 19:08:28 -07:00
|
|
|
RUN_TWICE_HOURLY = 60 * 30
|
2017-09-27 11:04:18 -06:00
|
|
|
|
2019-10-03 01:57:29 -06:00
|
|
|
APP = Celery('network')
|
2017-09-27 11:04:18 -06:00
|
|
|
|
2019-10-03 01:57:29 -06:00
|
|
|
APP.config_from_object('django.conf:settings', namespace='CELERY')
|
|
|
|
APP.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
2017-09-27 11:04:18 -06:00
|
|
|
|
|
|
|
|
2019-10-03 01:57:29 -06:00
|
|
|
@APP.on_after_finalize.connect
|
2019-09-29 08:09:10 -06:00
|
|
|
def setup_periodic_tasks(sender, **kwargs): # pylint: disable=W0613
|
2019-09-23 06:14:49 -06:00
|
|
|
from network.base.tasks import (
|
|
|
|
update_all_tle, fetch_data, clean_observations, station_status_update,
|
|
|
|
stations_cache_rates, notify_for_stations_without_results, sync_to_db
|
|
|
|
)
|
2017-09-27 11:04:18 -06:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(RUN_EVERY_TWO_HOURS, update_all_tle.s(), name='update-all-tle')
|
2017-09-27 11:04:18 -06:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(RUN_HOURLY, fetch_data.s(), name='fetch-data')
|
2017-09-27 11:04:18 -06:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(RUN_HOURLY, station_status_update.s(), name='station-status-update')
|
2018-01-09 09:15:36 -07:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(RUN_HOURLY, clean_observations.s(), name='clean-observations')
|
2017-09-27 11:04:18 -06:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(RUN_HOURLY, stations_cache_rates.s(), name='stations-cache-rates')
|
2018-09-02 14:05:15 -06:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(
|
|
|
|
settings.OBS_NO_RESULTS_CHECK_PERIOD,
|
|
|
|
notify_for_stations_without_results.s(),
|
|
|
|
name='notify_for_stations_without_results'
|
|
|
|
)
|
2019-03-05 11:51:13 -07:00
|
|
|
|
2019-09-23 06:14:49 -06:00
|
|
|
sender.add_periodic_task(RUN_TWICE_HOURLY, sync_to_db.s(), name='sync-to-db')
|