Move Monday department Slack notifications logic to GoalsProgressAlertsCron and remove duplicate implementation from exampleRoute.

This commit is contained in:
Jeppe Bundgaard
2026-03-02 12:25:10 +01:00
parent 78a6860eca
commit c1145495a0
2 changed files with 26 additions and 29 deletions
+26
View File
@@ -178,9 +178,35 @@ function SyncXLVaskModuleCron(): void
* Destinations: * Destinations:
* - SLACK: send to each department's configured webhook; if none, fallback to default Slack webhook. * - SLACK: send to each department's configured webhook; if none, fallback to default Slack webhook.
* - EMAIL/SMS: currently require explicit recipients in manual route; automatic cron will skip and log a warning. * - EMAIL/SMS: currently require explicit recipients in manual route; automatic cron will skip and log a warning.
* @throws Exception
*/ */
function GoalsProgressAlertsCron(): void function GoalsProgressAlertsCron(): void
{ {
// Run department overview goals mondays
if ((int)date('N') === 1) {
// Check if the time is between 07:00 and 17:00
if (!redis->exists('system:last_sent_monday_message') && (date('H') >= 7 && date('H') < 17)) {
// Set the key to expire in 24 hours
redis->set('system:last_sent_monday_message', (string)time());
redis->expire('system:last_sent_monday_message', 86400);
$department = new departments_o();
$days = 7;
// The time should be from 00:00:00 of the start date to 23:59:59 of the end date
$date_end = date('Y-m-d 23:59:59', strtotime("-1 days")); // Yesterday (Sunday) at 23:59:59
$date_start = date('Y-m-d 00:00:00', strtotime("-$days days")); // $days ago at 00:00:00
// Send the messages
$departments = [
1,
2,
3,
4,
5,
6,
7,
];
$department->sendSlackInternalStatisticNotification($date_start, $date_end, $departments);
}
}
// List all goals (not deleted) // List all goals (not deleted)
$goals = new department_goals_o(); $goals = new department_goals_o();
$rows = $goals->listObjects(function ($row) { $rows = $goals->listObjects(function ($row) {
@@ -24,35 +24,6 @@ class exampleRoute
{ {
$this->get('/example', function () { $this->get('/example', function () {
global $response; global $response;
// This is very hack-y, but it works for now
// Check if it's monday
if ((int)date('N') === 1) {
// Check if the time is between 07:00 and 17:00
if (!redis->exists('system:last_sent_monday_message') && (date('H') >= 7 && date('H') < 17)) {
// Set the key to expire in 24 hours
redis->set('system:last_sent_monday_message', (string)time());
redis->expire('system:last_sent_monday_message', 86400);
// Send the messages
$departments = [
1,
2,
3,
4,
5,
6,
7,
];
foreach ($departments as $department_id) {
$department = (new departments_o())->select((int)$department_id);
$days = 7;
// The time should be from 00:00:00 of the start date to 23:59:59 of the end date
$date_end = date('Y-m-d 23:59:59', strtotime("-1 days")); // Yesterday (Sunday) at 23:59:59
$date_start = date('Y-m-d 00:00:00', strtotime("-$days days")); // $days ago at 00:00:00
$department->sendPeriodStatisticsToSlack($date_start, $date_end); // Sends message to "daglig-ledelse".
}
//$department->sendSlackInternalStatisticNotification($date_start, $date_end, $departments);
}
}
$response->success(['message' => 'Hello World!']); $response->success(['message' => 'Hello World!']);
}); });