|
| 1 | +# Rebuild Missing Dataset Files |
| 2 | + |
| 3 | +This task rebuilds missing extracted files in GTFS datasets. |
| 4 | +It downloads datasets from their `hosted_url`, extracts all files, computes zipped and unzipped sizes, calculates hashes, uploads the files to a GCS bucket, and updates the database. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Task ID |
| 9 | + |
| 10 | +Use task ID: `rebuild_missing_dataset_files` |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +The function accepts the following payload: |
| 17 | + |
| 18 | +```json |
| 19 | +{ |
| 20 | + "dry_run": true, // [optional] If true, do not upload or modify the database (default: true) |
| 21 | + "after_date": "YYYY-MM-DD", // [optional] Only include datasets downloaded after this ISO date |
| 22 | + "latest_only": true // [optional] If true, only process the latest version of each dataset (default: true) |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +### Example: |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "dry_run": false, |
| 31 | + "after_date": "2025-07-01", |
| 32 | + "latest_only": true |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## What It Does |
| 39 | + |
| 40 | +For each GTFS dataset with missing file information (missing zipped/unzipped sizes or missing extracted files), this function: |
| 41 | + |
| 42 | +1. Downloads the `.zip` file from its `hosted_url` |
| 43 | +2. Computes the zipped size in bytes |
| 44 | +3. Extracts all GTFS files locally |
| 45 | +4. Computes the unzipped size in bytes |
| 46 | +5. Uploads each extracted file to a GCS bucket with the structure: |
| 47 | + |
| 48 | + ``` |
| 49 | + {feed-stable-id}/{dataset-stable-id}/extracted/{file_name} |
| 50 | + ``` |
| 51 | +6. Makes each file publicly accessible and stores its GCS URL |
| 52 | +7. Computes SHA256 hashes for each file |
| 53 | +8. Stores metadata in the `Gtfsfile` table for later use |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## GCP Environment Variables |
| 58 | + |
| 59 | +The function requires the following environment variables: |
| 60 | + |
| 61 | +| Variable | Description | |
| 62 | +| ---------------------- | ---------------------------------------------------------------------------- | |
| 63 | +| `DATASETS_BUCKET_NAME` | The name of the GCS bucket used to store extracted GTFS files | |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## Additional Notes |
| 68 | + |
| 69 | +* This function **disables SSL verification** when downloading files, as the sources are trusted internally. |
| 70 | +* Commits to the database occur in batches of 5 datasets to improve performance and avoid large transaction blocks. |
| 71 | +* If `dry_run` is enabled, no downloads, uploads, or DB modifications are performed. Only the number of affected datasets is logged. |
| 72 | +* The function is safe to rerun. It will only affect datasets missing required file metadata. |
0 commit comments