Skip to content

Commit

Permalink
Merge pull request #164 from wri/run-dist
Browse files Browse the repository at this point in the history
Schedule DIST-alerts sync for 1pm PST every day on production
  • Loading branch information
danscales authored Nov 25, 2024
2 parents c747ede + a67a18e commit cf9a875
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/datapump/sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..util.gcs import get_gs_file_as_text, get_gs_files, get_gs_subfolders
from ..util.models import ContentDateRange
from ..util.util import log_and_notify_error
from ..util.slack import slack_webhook


class Sync(ABC):
Expand Down Expand Up @@ -769,6 +770,8 @@ def build_jobs (self, config: DatapumpConfig) -> List[Job]:

jobs: List[Job] = []

slack_webhook("INFO", f"Starting dist-alerts jobs for {self.dataset_name}/{latest_release}")

job = RasterVersionUpdateJob(
# Current week alerts tile set
id=str(uuid1()),
Expand Down
25 changes: 24 additions & 1 deletion terraform/modules/datapump/cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Note: when it says est/EST here, it really means PST (Pacific Standard time)
# The hours in the cron() expression are in UTC.

resource "aws_cloudwatch_event_rule" "everyday-11-pm-est" {
name = substr("everyday-11-pm-est${local.name_suffix}", 0, 64)
description = "Run everyday at 11 pm EST"
Expand Down Expand Up @@ -26,6 +29,15 @@ resource "aws_cloudwatch_event_rule" "everyday-3-am-est" {
tags = local.tags
}

resource "aws_cloudwatch_event_rule" "everyday-1-pm-est" {
name = substr("everyday-1-pm-est${local.name_suffix}", 0, 64)
description = "Run everyday at 1 pm EST"
schedule_expression = "cron(0 21 ? * * *)"
tags = local.tags
}

# The count condition in each of the resources below ensures that the CloudWatch
# events only happen in production.
resource "aws_cloudwatch_event_target" "sync-areas" {
rule = aws_cloudwatch_event_rule.everyday-7-pm-est.name
target_id = substr("${local.project}-sync-areas${local.name_suffix}", 0, 64)
Expand Down Expand Up @@ -78,4 +90,15 @@ resource "aws_cloudwatch_event_target" "sync-integrated-alerts" {
input = "{\"command\": \"sync\", \"parameters\": {\"types\": [\"integrated_alerts\"]}}"
role_arn = aws_iam_role.datapump_states.arn
count = var.environment == "production" ? 1 : 0
}
}

# Run every day at 1pm PST, but new data from UMD should only be available on Saturday morning,
# so should only do a full run generating a new version once a week on Saturday/Sunday.
resource "aws_cloudwatch_event_target" "sync-dist-alerts" {
rule = aws_cloudwatch_event_rule.everyday-1-pm-est.name
target_id = substr("${local.project}-sync-umd-glad-dist-alerts${local.name_suffix}", 0, 64)
arn = aws_sfn_state_machine.datapump.id
input = "{\"command\": \"sync\", \"parameters\": {\"types\": [\"umd_glad_dist_alerts\"]}}"
role_arn = aws_iam_role.datapump_states.arn
count = var.environment == "production" ? 1 : 0
}

0 comments on commit cf9a875

Please sign in to comment.