Skip to content

Celery Tasks

Juuso Jokiniemi edited this page Oct 10, 2024 · 100 revisions

Convention used

The name of the task (registered) is marked as italic. e.g. smbackend_turku.tasks.import_mds_data is the register task name of the task that import MDS data.

smbackend_turku.tasks.import_mds_data

Tasks

About

To create a new task go to the admin page and create a new Periodic Task. It is possible to edit, disable, enable or delete the task afterwards.

Add periodic task

The results of the task can be monitored under the results.
Task results

Notifications of failed tasks.

Email notifications are sent to users that are in group 'CeleryAdmin'. The name of the group can be configured in settings.py with the variable 'CELERY_ADMIN_GROUP'. Note, the group must be created in the django admin and added to the users.

List of tasks to set up

MDS-data, addresses, counter data etc...

  • Municipalities
  • Index search columns
  • Import MDS Data
  • Addresses
  • Divisions
  • Counter data
  • Environment data
  • Exceptional situations
  • Unit maintenance(ski trail and ice track maintenance history)

Mobility data

Note it is possible to import all mobility data sources with one task, see.

  • Index mobility data search columns
  • Culture routes
  • Bicycle stands
  • Payment zones
  • Gas filling stations
  • Charging stations
  • Scooter restrictions
  • Speed limit zones
  • Accessories (public toilets, tables, benches, furniture groups)
  • Bike service stations
  • Parking places for car sharing cars
  • Bicycle networks
  • Marinas
  • Disabled and no staff parkings
  • Loading and unloading places
  • Lounaistieto shapefiles
  • Street maintenance history
  • Paavonpolkus
  • Outdoor trails
  • Traffic signs
  • Permits
  • Outdoor gym devices
  • Föli stops
  • Föli parkandride stops
  • Outdoor places
  • Parking machines
  • Playgrounds
  • Over and underpasses
  • School and kindergarten accessibility areas
  • Street area information
  • Parking garages
  • IoT-data

Note If the database is empty, all the tasks should be created and then run manually in the listed order to populate the database. The tasks are then continuously run according to how they are scheduled.

What should be set for every Task.

  • Name, descriptive name of the task
  • Task (registered), this is the name of task that is registered to Celery.
  • Crontab or Interval Schedule, Note Avoid scheduling tasks concurrently.
  • Start Datetime

Optionally:

  • Arguments
  • Setting the task to One-off task, e.g. will only be run once.

One-off task

Manually running tasks.

manually run task

  1. Select the task
  2. Choose Run selected tasks
  3. Press the button tun run the task After the Task has finished, the result can be found under task results.

One-off tasks

Index Search Columns, smbackend_turku.tasks.import_index_search_columns

Configure the task as one-off task and run it manually when needed. This task indexes the search columns and must be run after the first time the registered task smbackend_turku.tasks.import_mds_data is run. It can also be used if the search columns needs to be indexed for some reason. The search uses the search columns when searching data, if they are empty or outdated the search results will be faulty, most of the importers updates the search columns automatically. To hyphenate all addresses add the positional argument "--hyphenate_all_addresses".

Separately importing MDS data, smbackend_turku.tasks.turku_services_import

It is possible to separately import MDS entities, the entities names are: services, accessibility, units. To separately import a entity create a task with the registered name smbackend_turku.tasks.turku_services_import and pass the entity name as argument. e.g. to only import the units.

import only units

Deleting a externally imported source, smbackend_turku.tasks.delete_external_source

Create the task with the registered task smbackend_turku.tasks.delete_external_source and specify the name of the sources to be deleted in the arguments. e.g. this deletes gas_filling_stations.

delete gas_filling_stations argument

Periodic tasks

Municipalities, smbackend_turku.tasks.geo_import_municipalities

Configure the task and run it manually before setting up other tasks, as they depend on the data imported. This task should be configured as a periodic task to be run once a year. e.g. At 01:00 on day-of-month 2 in January.

once a year

Import MDS data, smbackend_turku.tasks.import_mds_data

It imports the Services, ServiceNodes, Units and Accessability data.

mds_data setup
MDS data should be imported once a day, add the following crontab schedule. Once a day at 1 a.m.

If MDS_data is imported the first time into a empty database the smbackend_turku.tasks.import_index_search_columns task must be run afterwards.

Divisions, smbackend_turku.tasks.import_division

Imports:

  • Major districts
  • Districts
  • Sub districts
  • Voting districts
  • Zip code areas
  • Finnish school districts
  • Swedish lower comprehensive school districts
  • Swedish upper comprehensive school districts

Addresses

Addresses should be imported ~3-4 times in a year. e.g. At 22:00 on day-of-month 4 in January, May, and September.

three times in a year

All addresses, smbackend_turku.tasks.import_addresses

This imports all the addresses in Southwest Finland and indexes search columns, note the import might take 8-10hours.

Separately importing addresses

There are three different registered tasks for address importing and the they should be imported in the following order.

  1. smbackend_turku.tasks.import_addresses, this imports addresses from the WFS server hosted by Turku. The data contains addresses of Kaarina and Turku.
  2. smbackend_turku.tasks.import_enriched_addresses, this enriches the addresses imported from the WFS server, i.e. Kaarina and Turku. This can be set to run 1h after the first address importer.
  3. smbackend_turku.tasks.import_geo_search_addresses, this imports the addresses of Southwest Finland, except for Turku and Kaarina, note this task might run for 7-9h.
  4. Finally manually run the task with registered task smbackend_turku.tasks.import_index_search_columns to update the search columns

Counter data

Telraam to csv, eco_counter.tasks.import_telraam_to_csv

Telraam data is imported from a csv file that is populated with the eco_counter.tasks.import_telraam_to_csv importer. The importer should be run every hour. Note, the importer runs hourly and populates daily CSV files. If the importer fails for a day zero(0) data will be populated. It is possible to start the importer with a from date argument, e.g., ["--from-date", "2023-06-05"]. The date is in YYYY-MM-DD format and the date cannot be more than three months in the past, which is the maximum length of history the Telraam API supports.

Initial, eco_counter.tasks.initial_import_counter_data

Before starting hourly imports, this one-off task must be run, this can be done manually. The task can also be used afterwards, if the hourly importer for some reason gets stuck etc. The task should be configured as a One-off Task. The task requires the counter(s) to be initialized as arguments. The counters are EC(Eco Counter), TC(Traffic Counter) and LC(Lam Counter). e.g., of arguments ["EC","TC"] would initialize and import the data for the Eco Counter and the Lam Counter.

Force initial, eco_counter.tasks.force_initial_import_counter_data

Same as the task above, except for that it discards the check if data is available.

Incremental, eco_counter.tasks.import_counter_data

The Interval Schedule should be set every hour for Eco-Counter(EC), Traffic-Counter(TC), Telraam-Counter(TR) and daily for LAM-Counter(LC) as the data gets updated on a daily basis. every hour The counter(s) to be imported must be set as arguments, e.g., ["TC","EC", "LC", "TR"] would import all counters, i.e., Eco Counter, Traffic Counter, Lam counter and Telraam counter.

Delete counter data, eco_counter.tasks.delete_counter_data

Task can be used to delete specific counter datas. The counter is set as argument, e.g.,["LC"] would delete Lam Counter datas.

Environment data

Imports AQ (Air Quality) and WO (Weather Observation) history. Import initial data and station with the task: environment_data.tasks.initial_import_with_stations. To import initial data without deleting/importing the stations run task: environment_data.tasks.initial_import. After the initial import the data should be imported every hour with the incremental task: environment_data.tasks.incremental_import. The importer task takes the data type as positional argument, e.g., to import Air Quality data the positional argument is ["AQ"] and for Weather Observations the positional argument is ["WO"]. The incremental tasks should be run every hour. To delete all the data (also stations) run task: environment_data.tasks.delete_all_data.

Exceptional situations

Traffic announcements, exceptional_situations.tasks.import_traffic_situations

Imports road works and traffic announcements in Southwest Finland from digitraffic.fi, the importer should be run once a hour.

Excavation permits, exceptional_situations.tasks.import_excavation_permits

Imports excavation permits in Turku area. The importer task should be run once a day.

Delete inactive announcements, exceptional_situations.tasks.delete_inactive_situations

The task can be used to delete inactive situations, deletes also the related announcements and locations. Todo, should this task be scheduled in the future?

Index mobility data Search Columns, mobility_data.tasks.index_mobility_data_search_columns

Configure the task as one-off task and run it manually when needed. This task indexes the search columns for mobility data tables and must be run after the mobility data search is taken into use. It can also be used if the search columns needs to be indexed for some reason.The search uses the search columns when searching data, if they are empty or outdated the search results will be faulty, most of the importers updates the search columns automatically.

Unit maintenance

Ski trails, maintenance.tasks.import_ski_trails

Before importing ski trail maintenance history the ski trails must be imported. The ski trails must also be imported if there are changes in the source data. The task can be set as a one-off task.

Ski trails maintenance history, maintenance.tasks.import_ski_trails_maintenance_history

Imports the maintenance history of ski trails, the importer should be set to run every 15 minutes.

Ice tracks maintenance history, maintenance.tasks.import_ice_tracks_maintenance_history

Imports the maintenance history of ice tracks, the import should be set to run every 15 minutes.

Importing all mobility datas.

To services list, smbackend_turku.tasks.import_external_sources_

Imports all external sources, i.e., mobility data sources to the services list.

To mobility view, mobility_data.tasks.import_mobility_data

Imports all mobility data source to the mobility view.

Culture Routes, mobility_data.tasks.import_culture_routes

Schedule the culture routes to be imported once a month. Optionally add argument "--delete" to delete all imported culture routes before importing new ones. e.g. At 02:00 on day-of-month 3

once a month

Bicycle Stands, smbackend_turku.tasks.import_bicycle_stands, source name bicycle_stands

Schedule to be imported once a month.

Payment Zones, mobility_data.tasks.import_payments_zones

Schedule to be imported once a year.

Gas Filling Stations, smbackend_turku.tasks.import_gas_filling_stations, source name gas_filling_stations

Schedule to be imported ~3 times a year.

Charging stations, smbackend_turku.tasks.import_charging_stations

The data should be imported when the data is changed.

Scooter restrictions, mobility_data.tasks.import_scooter_restrictions

Schedule to be imported once a month.

Speed limit zones, mobility_data.tasks.import_speed_limit_zones

Schedule to be imported twice a year.

Accessories, mobility_data.tasks.import_accessories

Imports benches, public toilets, tables and furniture groups. Schedule to be imported 4 times a year.

Bike service stations, smbackend_turku.tasks.import_bike_service_stations

The task should be run every time the static data is added or updated. This can also be done from the mobility data DataSource admin view when adding/updating the data.

Parking places for car sharing cars, mobility_data.tasks.import_share_car_parking_places

The task should be run every time the static data is added or updated. This can also be done from the mobility data DataSource admin view when adding/updating the data.

Bicycle networks, mobility_data.tasks.import_bicycle_networks

Imports brush salted and brush sanded bicycle networks. The task should be scheduled to be run 3 times a year.

Marinas, mobility_data.tasks.import_marinas

Imports marinas, guest marina and boat parking. The task should be run once a year(before the boating season) or if the data changes.

Disabled and no staff parkings, mobility_data.tasks.import_import_disabled_and_no_staff_parkings

Imports parking places that are for disabled and not for the staff, as the data is static the importer should be run when the data changes.

Loading and unloading places, mobility_data.tasks.import_loading_and_unloading_places

Imports loading and unloading places. The data is static and therefore the importer should be run when the data changes.

Lounaistieto shapefiles, mobility_data.tasks.import_lounaistieto_shapefiles

The importer should be set to run once a month. Currently is set to import:

  • Marinas in Southwest Finland
  • Slipways in Southwest Finland
  • Ferry routes in Southwest Finland
  • Fishing spots in Southwest Finland
  • Common ferry routes(yhteysalusreitti) in Southwest Finland
  • Ferry docks in Southwest Finland
  • Bus stop Southwest Finland

Street maintenance history, maintenance.tasks.import_street_maintenance_history

All street maintenance history is imported via the same importer. The importer should be run every 15 minutes. There are four providers:

  • Destia
  • Infraroad
  • Kuntec
  • YIT

The arguments are sent to the importer via kwargs as a dictionary(key value pair). The parameters(keys) are:

  • providers(mandatory), list of providers to import, e.g., {"providers": ["kuntec"]} or {"providers": ["infraroad", "destia"]}
  • history-size, number of days to fetch, e.g., {"providers": ["kuntec"], "history-size": 1}. Note the value is an integer and the max value is 31.
  • fetch-size, (only available for Destia and Infraroad), The number of works(point data with a timestamp and a events) to be fetched for every unit. e.g., {"providers": ["destia"], "fetch-size": 1000}. The default value is 10_000 and the value is of type int.

Example of kwargs, imports providers destia and infraroad with history-size 1: example of kwargs importing destia and infraroad with history-size 1.

Example 2 of kwargs, imports only provider kuntec.: Example of kwargs, importing only one provider.

Note, only the MaintenanceWorks and MaintenanceUnits for the given provider from the latest import are stored and the rest are deleted. The GeometryHistory is generated only if more than one MaintenanceWork is created.

Delete street maintenance history, maintenance.tasks.delete_street_maintenance_history

This task can be used to delete street maintenance history for a provider. The name of the provider must be given as argument, e.g, ["DESTIA"].

Paavonpolkus, mobility_data.tasks.import_paavonpolkus

The data should be imported if changed, otherwise once a year.

Outdoor trails, mobility_data.tasks.import_outdoor_trails

Imports paddling, hiking, nature and fitness trails. The importer should be run once a month.

Traffic signs, mobility_data.tasks.import_traffic_signs

Importer should be run once a month. Imports following signs:

  • Crosswalk
  • Disabled parking
  • Route for disabled
  • Parking terminal
  • Ticket machine
  • Local traffic bus stop
  • Long-distance bus stop
  • Parking forbidden
  • Obligation to use parking disc
  • Paid parking
  • Parking lot
  • Railway level crossing without booms
  • Railway level crossing with booms
  • Single track railway level crossing with booms
  • taxi stand

Permits, mobility_data.tasks.import_permits

The importer should be run once a week. Imports following permits:

  • ExcavationPermit
  • FencePermit
  • PlacementPermit

Outdoor gym devices, mobility_data.tasks.import_outdoor_gym_devices

The data is "imported" from the services.units model. The ID of the Unit is stored to the mobile_unit row.

Föli stops, mobility_data.tasks.import_foli_stops

Imports the Föli stops.

Föli park and ride stops, mobility_data.tasks.import_foli_parkandride_stops

Import the park and ride stops for bikes and cars.

Outdoor places, mobility_data.tasks.import_outdoor_places

Imports:

  • Barbecue places
  • Lean-tos The task can be set to be run once a month.

Parking machines, mobility_data.tasks.import_parking_machines

The importer imports from a static GEJSON file, so the importer should be run every time the data changes. The data can be updated by modifying the DataSource table from the admin.

Playgrounds, mobility_data.tasks.import_playgrounds

Imports the playgrounds in the city of Turku, the importer can be run once a month.

Over and underpasses, mobility_data.tasks.import_under_and_overpasses

Imports both under and overpasses from Väylävirasto. The importer could be run every month.

School and kindergarten accessibility areas, mobility_data.tasks.import_school_and_kindergarten_accessibility_areas

Imports school and kindergarten accessibility areas. The importer should be run every time the data has changed(yearly?).

Street area information, mobility_data.tasks.import_street_area_information

Imports information (owner, street maintenance class etc..). The importer should be run once a month.

Parking garages, mobility_data.tasks.import_parking_garages

As the source data is a static CSV file, the importer should be run when the source data is updated.

IoT-Data, iot.tasks.import_iot_data

Create a task for every IoT data source. The scheduling depends on how often the source data is updated and what is reasonable to keep the data up to date. Every task needs the three letter name of the IoT data source to be added to the arguments. See, creating IoT data sources.

e.g., to add a IoT data source with the three letter name R24. Note the quotes surrounding the name(R24). arguments

These data sources are currently in active use.

Note, the type_name, e.g., R24 must not change, as they are hard coded in the front end.

  • R24 (24Rent shared use cars). This is updated every hour.
  • CBI (information about city bike stations). This is updated every 30 minutes.
  • CBS (statistics of every city bike station). This is updated every 30 minutes.
  • FAA (flights that will arrive to Turku Airport). This is updated every hour.
  • FAD (flights that will depart from Turku Airport). This is updated every hour.
  • SDR (scooters by Ryde). This is updated every 30 minutes.
  • SDV (scooters by Voi).
  • SDT (scooters by Tier).

Deleting mobility data, mobility_data.tasks.delete_mobility_data

Whit this task it is possible to delete mobility units for given content types. Give content type name as argument e.g., ["PaavonPolku"], would delete all the mobile units that are 'Paavonpolku' content type. It is also possible to give many content types as argument e.g., ["PaavonPolku", "FitnessTrail"].

Clone this wiki locally