fix(notifications): use per-type dedup window, 24h for scheduler failures
Change DEDUPE_TYPES from bool to int|true — int value overrides the default 30-min window. scheduler.job_failed uses 1440 min (24h) so admins receive at most one notification per failed job per day. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,13 +9,15 @@ class NotificationService
|
|||||||
{
|
{
|
||||||
private const MESSAGE_META_KEY = '__message';
|
private const MESSAGE_META_KEY = '__message';
|
||||||
private const DEDUPE_WINDOW_MINUTES = 30;
|
private const DEDUPE_WINDOW_MINUTES = 30;
|
||||||
|
|
||||||
|
/** @var array<string, int|true> Type → dedup window in minutes (true = default window). */
|
||||||
private const DEDUPE_TYPES = [
|
private const DEDUPE_TYPES = [
|
||||||
'user.created' => true,
|
'user.created' => true,
|
||||||
'user.deleted' => true,
|
'user.deleted' => true,
|
||||||
'user.activated' => true,
|
'user.activated' => true,
|
||||||
'user.deactivated' => true,
|
'user.deactivated' => true,
|
||||||
'user.assignment_changed' => true,
|
'user.assignment_changed' => true,
|
||||||
'scheduler.job_failed' => true,
|
'scheduler.job_failed' => 1440,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -233,6 +235,9 @@ class NotificationService
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$windowMinutes = self::DEDUPE_TYPES[$type];
|
||||||
|
$windowMinutes = is_int($windowMinutes) && $windowMinutes > 0 ? $windowMinutes : self::DEDUPE_WINDOW_MINUTES;
|
||||||
|
|
||||||
$tenantScope = $tenantId !== null && $tenantId > 0 ? $tenantId : 0;
|
$tenantScope = $tenantId !== null && $tenantId > 0 ? $tenantId : 0;
|
||||||
$raw = implode('|', [
|
$raw = implode('|', [
|
||||||
'recipient:' . $recipientUserId,
|
'recipient:' . $recipientUserId,
|
||||||
@@ -243,7 +248,7 @@ class NotificationService
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'fingerprint' => hash('sha256', $raw),
|
'fingerprint' => hash('sha256', $raw),
|
||||||
'bucket' => intdiv(time(), self::DEDUPE_WINDOW_MINUTES * 60),
|
'bucket' => intdiv(time(), $windowMinutes * 60),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user