Skip to content

Commit 5d2de6e

Browse files
authored
feat: create a gcp function to generate the pmtiles of a single dataset (#1305)
1 parent 3638564 commit 5d2de6e

File tree

7 files changed

+1098
-16
lines changed

7 files changed

+1098
-16
lines changed

functions-python/tasks_executor/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,28 @@ The function receive the following payload:
1313
}
1414
```
1515

16-
Example:
16+
Examples:
1717

1818
```json
1919
{
2020
"task": "rebuild_missing_validation_reports",
2121
"payload": {
22-
"dry_run": true,
23-
"filter_after_in_days": 14,
24-
"filter_statuses": ["active", "inactive", "future"]
25-
}
22+
"dry_run": true,
23+
"filter_after_in_days": 14,
24+
"filter_statuses": ["active", "inactive", "future"]
25+
}
2626
}
2727
```
2828
```json
2929
{
3030
"task": "rebuild_missing_bounding_boxes",
3131
"payload": {
32-
"dry_run": true,
33-
"after_date": "2025-06-01"
34-
}
32+
"dry_run": true,
33+
"after_date": "2025-06-01"
34+
}
3535
}
36+
```
37+
```json
3638
{
3739
"task": "refresh_materialized_view",
3840
"payload": {
@@ -44,7 +46,7 @@ Example:
4446
To get the list of supported tasks use:
4547
```json
4648
{
47-
"name": "list_tasks",
48-
"payload": {}
49+
"name": "list_tasks",
50+
"payload": {}
4951
}
5052
```

functions-python/tasks_executor/function_config.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
"name": "tasks_executor",
33
"description": "The Tasks Executor function runs maintenance tasks avoiding the creation of multiple functions for one-time execution",
44
"entry_point": "tasks_executor",
5-
"timeout": 540,
6-
"memory": "4Gi",
5+
"timeout": 1000,
6+
"memory": "8Gi",
77
"trigger_http": true,
88
"include_folders": ["helpers"],
99
"include_api_folders": ["database_gen", "database", "common"],
10-
"environment_variables": [],
10+
"environment_variables": [
11+
{
12+
"key": "DATASETS_BUCKET_NAME"
13+
}
14+
],
1115
"secret_environment_variables": [
1216
{
1317
"key": "FEEDS_DATABASE_URL"
@@ -21,5 +25,5 @@
2125
"max_instance_request_concurrency": 1,
2226
"max_instance_count": 1,
2327
"min_instance_count": 0,
24-
"available_cpu": 1
28+
"available_cpu": 2
2529
}

functions-python/tasks_executor/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ flask
2525
google-cloud-storage
2626

2727
# Configuration
28-
python-dotenv==1.0.0
28+
python-dotenv==1.0.0
29+
tippecanoe
30+

functions-python/tasks_executor/src/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from tasks.missing_bounding_boxes.rebuild_missing_bounding_boxes import (
3232
rebuild_missing_bounding_boxes_handler,
3333
)
34-
34+
from tasks.pmtiles_builder.build_pmtiles import build_pmtiles_handler
3535

3636
init_logger()
3737
LIST_COMMAND: Final[str] = "list"
@@ -63,6 +63,10 @@
6363
"description": "Rebuilds missing dataset files for GTFS datasets.",
6464
"handler": rebuild_missing_dataset_files_handler,
6565
},
66+
"build_pmtiles": {
67+
"description": "Build pmtiles for a given dataset.",
68+
"handler": build_pmtiles_handler,
69+
},
6670
}
6771

6872

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Build pmtile for a specific GTFS dataset
2+
3+
This task generates the pmtiles for a provided dataset.
4+
pmtiles are used for displaying routes and stops in the UI
5+
6+
## Task ID
7+
Use task Id: `build_pmtiles`
8+
9+
## Usage
10+
The function receive the following payload:
11+
```
12+
{
13+
"feed_stable_id": str,
14+
"dataset_stable_id*: str
15+
}
16+
```
17+
18+
Example:
19+
```json
20+
{
21+
"feed_stable_id": "mdb-1004",
22+
"dataset_stable_id": "mdb-1004-202507081807"
23+
}
24+
```
25+
26+
The task will verify that the dataset stable id starts with the feed stable id (mdb-1004 in our example)
27+
28+
# GCP environment variables
29+
The function uses the following environment variables:
30+
- `ENV`: The environment to use. It can be `dev`, `staging` or `prod`. Default is `dev`.
31+
- `DATASETS_BUCKET_NAME`: The bucket name where the datasets are stored. The task will fail if this is not defined. The variable has to include the suffix, like `-dev`, `-qa` or `-prod`.

0 commit comments

Comments
 (0)