Skip to content

Commit

Permalink
Add heartbeat monitor for statuscake
Browse files Browse the repository at this point in the history
  • Loading branch information
johnake committed Sep 3, 2024
1 parent 4a8b6e1 commit d97cb3d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 7 additions & 4 deletions app/jobs/heartbeat_job.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Writes "Heartbeat job performed" to the logs every minute. This message is
# evidence that the worker is working properly. We can use a log alerting tool
# to alert us if too much time passes without seeing one of these messages.
require "net/http"

class HeartbeatJob < CronJob
self.cron_expression = "* * * * *"

queue_as :heartbeat

def perform
logger.info "Heartbeat job performed"
if ENV.key?("HEARTBEAT_CHECK_URL") # Not available in dev and review environments
url = URI.parse(ENV["HEARTBEAT_CHECK_URL"])
req = Net::HTTP::Get.new(url.to_s)
Net::HTTP.start(url.host, url.port) { |http| http.request(req) }
end
end
end
11 changes: 8 additions & 3 deletions terraform/application/application.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ module "application_configuration" {
PGSSLMODE = local.postgres_ssl_mode
CANONICAL_HOSTNAME = local.canonical_hostname
})
secret_variables = {
DATABASE_URL = module.postgres.url
}
secret_variables = merge(
{
DATABASE_URL = module.postgres.url
},
var.enable_monitoring ? {
HEARTBEAT_CHECK_URL = module.statuscake[0].heartbeat_check_urls[local.heartbeat_check_name]
} : {}
)
}

module "web_application" {
Expand Down
2 changes: 2 additions & 0 deletions terraform/application/statuscake.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ module "statuscake" {
ssl_urls = compact([var.external_url])

contact_groups = var.statuscake_contact_groups

heartbeat_names = [local.heartbeat_check_name]
}
1 change: 1 addition & 0 deletions terraform/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ locals {
canonical_hostname = var.canonical_hostname != null ? var.canonical_hostname : "${var.service_name}-${var.environment}-web.test.teacherservices.cloud"
app_env_values_from_yml = yamldecode(file("${path.module}/config/${var.config}_app_env.yml"))
app_env_values = merge(local.app_env_values_from_yml)
heartbeat_check_name = "heartbeat-check"
}

0 comments on commit d97cb3d

Please sign in to comment.