Skip to content

Commit f3a407e

Browse files
committed
Added a GCP scheduler for export_csv
1 parent 3f44367 commit f3a407e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

infra/functions-python/main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,31 @@ resource "google_cloudfunctions2_function" "export_csv" {
891891
}
892892
}
893893
}
894+
}
895+
894896

897+
resource "google_cloud_scheduler_job" "export_csv_scheduler" {
898+
name = "export-csv-scheduler-${var.environment}"
899+
description = "Schedule the export_csv function"
900+
time_zone = "Etc/UTC"
901+
schedule = var.export_csv_schedule
902+
region = var.gcp_region
903+
# paused = var.environment == "prod" ? false : true
904+
depends_on = [google_cloudfunctions2_function.export_and_upload_csv, google_cloudfunctions2_function_iam_member.export_csv_invoker]
905+
http_target {
906+
http_method = "POST"
907+
uri = google_cloudfunctions2_function.export_csv.url
908+
oidc_token {
909+
service_account_email = google_service_account.functions_service_account.email
910+
}
911+
headers = {
912+
"Content-Type" = "application/json"
913+
}
914+
}
915+
attempt_deadline = "320s"
895916
}
896917

918+
897919
# IAM entry for all users to invoke the function
898920
resource "google_cloudfunctions2_function_iam_member" "tokens_invoker" {
899921
project = var.project_id
@@ -1050,4 +1072,12 @@ resource "google_project_iam_member" "datastore_owner" {
10501072
project = var.project_id
10511073
role = "roles/datastore.owner"
10521074
member = "serviceAccount:${google_service_account.functions_service_account.email}"
1075+
}
1076+
1077+
resource "google_cloudfunctions2_function_iam_member" "export_csv_invoker" {
1078+
project = var.project_id
1079+
location = var.gcp_region
1080+
cloud_function = google_cloudfunctions2_function.export_csv.name
1081+
role = "roles/cloudfunctions.invoker"
1082+
member = "serviceAccount:${google_service_account.functions_service_account.email}"
10531083
}

infra/functions-python/vars.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ variable "gbfs_scheduler_schedule" {
6767

6868
variable "transitland_scraping_schedule" {
6969
type = string
70-
description = "Schedule for the GBFS scheduler job"
70+
description = "Schedule Transitland scraping job"
7171
default = "0 0 3 * *" # every month on the 3rd day at 00:00
7272
}
7373

@@ -79,4 +79,10 @@ variable "transitland_api_key" {
7979
variable "operations_oauth2_client_id" {
8080
type = string
8181
description = "value of the OAuth2 client id for the Operations API"
82+
}
83+
84+
variable "export_csv_schedule" {
85+
type = string
86+
description = "Schedule the export_csv function"
87+
default = "*/3 * * * *" # every 3 minutes for testing. Change before merging.
8288
}

0 commit comments

Comments
 (0)