Skip to content

Commit

Permalink
DDLS-401 - Fix Inactive Lay Cleanup Job (#1746)
Browse files Browse the repository at this point in the history
* DDLS-401 - Drops & re-adds constraint so ON DELETE can be specified

* DDLS-401 - Re-enables zero activity job

* DDLS-401 - Updates ARN to point at correct notification service
  • Loading branch information
Raffers authored Dec 2, 2024
1 parent be47730 commit 7ef8d31
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 62 deletions.
2 changes: 1 addition & 1 deletion api/app/src/Entity/Deputy.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class Deputy
/**
* @JMS\Type("App\Entity\User")
*
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="deputy")
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="deputy", cascade={"remove"})
*
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
Expand Down
31 changes: 31 additions & 0 deletions api/app/src/Migrations/Version284.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version284 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adjusts fk constraint so cleanup job can correctly execute';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE deputy DROP CONSTRAINT fk_28fa6b9fa76ed395;');
$this->addSql('ALTER TABLE deputy ADD CONSTRAINT fk_28fa6b9fa76ed395 FOREIGN KEY (user_id) REFERENCES dd_user (id) ON DELETE CASCADE;');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE deputy DROP CONSTRAINT fk_28fa6b9fa76ed395;');
$this->addSql('ALTER TABLE deputy ADD CONSTRAINT fk_28fa6b9fa76ed395 FOREIGN KEY (user_id) REFERENCES dd_user (id);');
}
}
70 changes: 35 additions & 35 deletions terraform/environment/region/cloudwatch_scheduled_events.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,41 +115,41 @@ resource "aws_cloudwatch_event_target" "delete_inactive_users" {

# Delete zero activity users - Temp disabled due to change in data structure linking additional tables.

#resource "aws_cloudwatch_event_rule" "delete_zero_activity_users" {
# name = "delete-zero-activity-users-${local.environment}"
# description = "Delete zero activity users in ${terraform.workspace}"
# schedule_expression = "cron(20 6 * * ? *)"
# tags = var.default_tags
#}
#
#resource "aws_cloudwatch_event_target" "delete_zero_activity_users" {
# rule = aws_cloudwatch_event_rule.delete_zero_activity_users.name
# arn = aws_ecs_cluster.main.arn
# role_arn = aws_iam_role.events_task_runner.arn
#
# ecs_target {
# task_count = 1
# task_definition_arn = aws_ecs_task_definition.api.arn
# launch_type = "FARGATE"
# platform_version = "1.4.0"
#
# network_configuration {
# security_groups = [module.api_service_security_group.id]
# subnets = data.aws_subnet.private[*].id
# assign_public_ip = false
# }
# }
# input = jsonencode(
# {
# "containerOverrides" : [
# {
# "name" : "api_app",
# "command" : ["sh", "scripts/task_run_console_command.sh", "digideps:delete-zero-activity-users"]
# }
# ]
# }
# )
#}
resource "aws_cloudwatch_event_rule" "delete_zero_activity_users" {
name = "delete-zero-activity-users-${local.environment}"
description = "Delete zero activity users in ${terraform.workspace}"
schedule_expression = "cron(20 6 * * ? *)"
tags = var.default_tags
}

resource "aws_cloudwatch_event_target" "delete_zero_activity_users" {
rule = aws_cloudwatch_event_rule.delete_zero_activity_users.name
arn = aws_ecs_cluster.main.arn
role_arn = aws_iam_role.events_task_runner.arn

ecs_target {
task_count = 1
task_definition_arn = aws_ecs_task_definition.api.arn
launch_type = "FARGATE"
platform_version = "1.4.0"

network_configuration {
security_groups = [module.api_service_security_group.id]
subnets = data.aws_subnet.private[*].id
assign_public_ip = false
}
}
input = jsonencode(
{
"containerOverrides" : [
{
"name" : "api_app",
"command" : ["sh", "scripts/task_run_console_command.sh", "digideps:delete-zero-activity-users"]
}
]
}
)
}

# Resubmit re-submittable error documents

Expand Down
52 changes: 26 additions & 26 deletions terraform/environment/region/cloudwatch_scheduled_events_checks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,32 @@ resource "aws_cloudwatch_event_target" "delete_inactive_users_check" {

# Delete zero activity users check - Temp disabled due to change in data structure linking additional tables.

#resource "aws_cloudwatch_event_rule" "delete_zero_activity_users_check" {
# name = "check-delete-zero-activity-users-${terraform.workspace}"
# description = "Execute the delete zero activity users check for ${terraform.workspace}"
# schedule_expression = "cron(12 09 * * ? *)"
# is_enabled = var.account.is_production == 1 ? true : false
#}
#
#resource "aws_cloudwatch_event_target" "delete_zero_activity_users_check" {
# target_id = "check-delete-zero-activity-users-${terraform.workspace}"
# arn = data.aws_lambda_function.slack_lambda.arn
# rule = aws_cloudwatch_event_rule.delete_zero_activity_users_check.name
# input = jsonencode(
# {
# scheduled-event-detail = {
# job-name = "delete_zero_activity_users_check"
# log-group = terraform.workspace,
# log-entries = ["delete_zero_activity_users"],
# search-timespan = "24 hours",
# bank-holidays = "true",
# channel-identifier-absent = "team",
# channel-identifier-success = "scheduled-jobs",
# channel-identifier-failure = "team"
# }
# }
# )
#}
resource "aws_cloudwatch_event_rule" "delete_zero_activity_users_check" {
name = "check-delete-zero-activity-users-${terraform.workspace}"
description = "Execute the delete zero activity users check for ${terraform.workspace}"
schedule_expression = "cron(12 09 * * ? *)"
is_enabled = var.account.is_production == 1 ? true : false
}

resource "aws_cloudwatch_event_target" "delete_zero_activity_users_check" {
target_id = "check-delete-zero-activity-users-${terraform.workspace}"
arn = data.aws_lambda_function.monitor_notify_lambda.arn
rule = aws_cloudwatch_event_rule.delete_zero_activity_users_check.name
input = jsonencode(
{
scheduled-event-detail = {
job-name = "delete_zero_activity_users_check"
log-group = terraform.workspace,
log-entries = ["delete_zero_activity_users"],
search-timespan = "24 hours",
bank-holidays = "true",
channel-identifier-absent = "team",
channel-identifier-success = "scheduled-jobs",
channel-identifier-failure = "team"
}
}
)
}

# Resubmit re-submittable error documents check

Expand Down

0 comments on commit 7ef8d31

Please sign in to comment.