Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions crcr/aws/sweeper.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Active sweeper: EventBridge fires the callback lambda on a fixed schedule so it
# can scan the Redis ZSET of in-progress jobs and time out any "zombie" jobs whose
# expected-timeout score has elapsed. The callback handler routes on the constant
# payload below to branch into the cleanup logic.

resource "aws_cloudwatch_event_rule" "sweeper" {
name = "crcr-sweeper-${var.environment}"
description = "Periodic trigger for the cross-repo-ci callback lambda to reap timed-out jobs"
schedule_expression = "rate(${var.sweeper_interval_minutes} minutes)"
tags = local.tags
}

resource "aws_cloudwatch_event_target" "sweeper" {
rule = aws_cloudwatch_event_rule.sweeper.name
target_id = "crcr-callback-sweeper"
arn = aws_lambda_function.callback.arn

input = jsonencode({
source = "crcr.sweeper"
})
}

resource "aws_lambda_permission" "sweeper_invoke" {
statement_id = "AllowEventBridgeSweeperInvoke"
function_name = aws_lambda_function.callback.function_name
action = "lambda:InvokeFunction"
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.sweeper.arn
}
11 changes: 11 additions & 0 deletions crcr/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ variable "oot_status_ttl" {
type = number
default = 259200
}

variable "sweeper_interval_minutes" {
description = "How often EventBridge triggers the callback lambda to reap timed-out jobs (minutes)"
type = number
default = 10

validation {
condition = var.sweeper_interval_minutes >= 2
error_message = "sweeper_interval_minutes must be >= 2; more frequent sweeps reap too few zombies to be worthwhile."
}
}
Loading