Introduce purge task

pull/78/head
Konstantin Gründger 2019-03-18 08:37:19 +01:00
rodzic 250e0cf738
commit 738fa5bc04
3 zmienionych plików z 28 dodań i 7 usunięć

Wyświetl plik

@ -58,11 +58,12 @@ For best performance you should use [TimescaleDB](https://www.timescale.com), wh
8. Get world elevation data (needed for AGL calculation) 8. Get world elevation data (needed for AGL calculation)
Sources: There are many sources for DEM data. It is important that the spatial reference system (SRID) is the same as the database which is 4326. Sources: There are many sources for DEM data. It is important that the spatial reference system (SRID) is the same as the database which is 4326.
The [GMTED2010 Viewer](https://topotools.cr.usgs.gov/gmted_viewer/viewer.htm) provides data for the world. Just download the data you need. The [GMTED2010 Viewer](https://topotools.cr.usgs.gov/gmted_viewer/viewer.htm) provides data for the world with SRID 4326. Just download the data you need.
For Europe we can get the DEM as GeoTIFF files from the [European Environment Agency](https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1). For Europe we can get the DEM as GeoTIFF files from the [European Environment Agency](https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1).
Because the SRID of these files is 3035 and we want 4326 we have to convert them (next step) Because the SRID of these files is 3035 and we want 4326 we have to convert them (next step)
9. Convert the elevation data into correct SRID 9. Optional: Convert the elevation data into correct SRID
We convert elevation from one SRID (here: 3035) to target SRID (4326): We convert elevation from one SRID (here: 3035) to target SRID (4326):

Wyświetl plik

@ -18,12 +18,11 @@ logger = get_task_logger(__name__)
@celery.task(name='update_takeoff_landings') @celery.task(name='update_takeoff_landings')
def update_takeoff_landings(): def update_takeoff_landings(delta):
"""Compute takeoffs and landings.""" """Compute takeoffs and landings."""
now = datetime.datetime.now() now = datetime.datetime.utcnow()
yesterday = now - datetime.timedelta(days=1) takeoff_update_entries(session=db.session, start=now-delta, end=now, logger=logger)
takeoff_update_entries(session=db.session, start=yesterday, end=now, logger=logger)
@celery.task(name='update_logbook_entries') @celery.task(name='update_logbook_entries')
@ -53,3 +52,18 @@ def update_receivers_country_code():
"""Update country code in receivers table if None.""" """Update country code in receivers table if None."""
receivers_update_country_code(session=db.session, logger=logger) receivers_update_country_code(session=db.session, logger=logger)
@celery.task(name='purge_old_data')
def purge_old_data(age):
"""Delete AircraftBeacons and ReceiverBeacons older than given 'age'."""
from ogn_python.model import AircraftBeacon, ReceiverBeacon
now = datetime.datetime.utcnow()
db.session(AircraftBeacon) \
.filter(AircraftBeacon.timestamp < now - age) \
.delete()
db.session(ReceiverBeacon) \
.filter(ReceiverBeacon.timestamp < now - age) \
.delete()

Wyświetl plik

@ -11,7 +11,7 @@ from datetime import timedelta
CELERYBEAT_SCHEDULE = { CELERYBEAT_SCHEDULE = {
'update-ddb': { 'update-ddb': {
'task': 'import_ddb', 'task': 'import_ddb',
'schedule': timedelta(minutes=1), 'schedule': timedelta(hours=1),
}, },
'update-country-codes': { 'update-country-codes': {
'task': 'update_receivers_country_code', 'task': 'update_receivers_country_code',
@ -20,6 +20,7 @@ CELERYBEAT_SCHEDULE = {
'update-takeoff-and-landing': { 'update-takeoff-and-landing': {
'task': 'update_takeoff_landings', 'task': 'update_takeoff_landings',
'schedule': timedelta(minutes=1), 'schedule': timedelta(minutes=1),
'kwargs': {'delta': timedelta(minutes=10)}
}, },
'update-logbook': { 'update-logbook': {
'task': 'update_logbook_entries', 'task': 'update_logbook_entries',
@ -29,4 +30,9 @@ CELERYBEAT_SCHEDULE = {
'task': 'update_logbook_max_altitude', 'task': 'update_logbook_max_altitude',
'schedule': timedelta(minutes=1), 'schedule': timedelta(minutes=1),
}, },
#'purge_old_data': {
# 'task': 'purge_old_data',
# 'schedule': timedelta(minutes=10),
# 'kwargs': {'age': timedelta(days=2)}
#},
} }