Skip to content

Commit

Permalink
feat: added scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y committed Dec 2, 2024
1 parent b1be391 commit f25188d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions infra/functions-python/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,27 @@ resource "google_cloud_scheduler_job" "gbfs_validator_batch_scheduler" {
attempt_deadline = "320s"
}

resource "google_cloud_scheduler_job" "transit_land_scraping_scheduler" {
name = "transitland-scraping-scheduler-${var.environment}"
description = "Schedule the transitland scraping function"
time_zone = "Etc/UTC"
schedule = var.transitland_scraping_schedule
region = var.gcp_region
paused = var.environment == "prod" ? false : true
depends_on = [google_cloudfunctions2_function.feed_sync_dispatcher_transitland, google_cloudfunctions2_function_iam_member.transitland_feeds_dispatcher_invoker]
http_target {
http_method = "POST"
uri = google_cloudfunctions2_function.feed_sync_dispatcher_transitland.url
oidc_token {
service_account_email = google_service_account.functions_service_account.email
}
headers = {
"Content-Type" = "application/json"
}
}
attempt_deadline = "320s"
}

# 5.3 Create function that subscribes to the Pub/Sub topic
resource "google_cloudfunctions2_function" "gbfs_validator_pubsub" {
name = "${local.function_gbfs_validation_report_config.name}-pubsub"
Expand Down Expand Up @@ -762,6 +783,14 @@ resource "google_cloudfunctions2_function_iam_member" "gbfs_validator_batch_invo
member = "serviceAccount:${google_service_account.functions_service_account.email}"
}

resource "google_cloudfunctions2_function_iam_member" "transitland_feeds_dispatcher_invoker" {
project = var.project_id
location = var.gcp_region
cloud_function = google_cloudfunctions2_function.feed_sync_dispatcher_transitland.name
role = "roles/cloudfunctions.invoker"
member = "serviceAccount:${google_service_account.functions_service_account.email}"
}

# Grant permissions to the service account to publish to the pubsub topic
resource "google_pubsub_topic_iam_member" "functions_publisher" {
for_each = {
Expand Down
6 changes: 6 additions & 0 deletions infra/functions-python/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ variable "gbfs_scheduler_schedule" {
default = "0 0 1 * *" # every month on the first day at 00:00
}

variable "transitland_scraping_schedule" {
type = string
description = "Schedule for the GBFS scheduler job"
default = "0 0 3 * *" # every month on the 3rd day at 00:00
}

variable "transitland_api_key" {
type = string
description = "Transitland API key"
Expand Down

0 comments on commit f25188d

Please sign in to comment.