Files
breadcrumb-the-shire/modules/notifications/lib/Module/Notifications/NotificationsContainerRegistrar.php
fs 97ff3ce135 feat(scheduler): dispatch event on job failure, notify admins via notifications module
Add ?ModuleEventDispatcher to SchedulerRunService (fail-open, nullable).
Dispatch scheduler.job_failed event when a job fails with payload:
job_id, job_key, label, error_code, error_message, trigger_type.

New SchedulerJobFailedNotificationListener in notifications module
creates in-app admin notifications for users with JOBS_MANAGE
permission, scoped per tenant, with 30-min dedup per job_key.

Also fixes audit module manifest: system_audit_purge job_key was
mismatched (audit_system_purge vs system_audit_purge in DB).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 12:26:54 +02:00

74 lines
3.8 KiB
PHP

<?php
namespace MintyPHP\Module\Notifications;
use MintyPHP\App\AppContainer;
use MintyPHP\App\Container\ContainerRegistrar;
use MintyPHP\Module\Notifications\Handler\NotificationCleanupJobHandler;
use MintyPHP\Module\Notifications\Listeners\UserActivatedNotificationListener;
use MintyPHP\Module\Notifications\Listeners\UserAssignmentChangedNotificationListener;
use MintyPHP\Module\Notifications\Listeners\UserCreatedNotificationListener;
use MintyPHP\Module\Notifications\Listeners\UserDeactivatedNotificationListener;
use MintyPHP\Module\Notifications\Listeners\SchedulerJobFailedNotificationListener;
use MintyPHP\Module\Notifications\Listeners\UserDeletedNotificationListener;
use MintyPHP\Module\Notifications\Repository\NotificationRepository;
use MintyPHP\Module\Notifications\Service\NotificationService;
use MintyPHP\Repository\Tenant\UserTenantRepository;
use MintyPHP\Repository\User\UserReadRepository;
use MintyPHP\Service\Access\PermissionService;
final class NotificationsContainerRegistrar implements ContainerRegistrar
{
public function register(AppContainer $container): void
{
$container->set(NotificationsAuthorizationPolicy::class, static fn (AppContainer $c): NotificationsAuthorizationPolicy => new NotificationsAuthorizationPolicy(
$c->get(PermissionService::class)
));
$container->set(NotificationRepository::class, static fn (): NotificationRepository => new NotificationRepository());
$container->set(NotificationService::class, static fn (AppContainer $c): NotificationService => new NotificationService(
$c->get(NotificationRepository::class),
$c->get(UserTenantRepository::class)
));
$container->set(NotificationCleanupJobHandler::class, static fn (AppContainer $c): NotificationCleanupJobHandler => new NotificationCleanupJobHandler(
$c->get(NotificationService::class)
));
$container->set(UserCreatedNotificationListener::class, static fn (AppContainer $c): UserCreatedNotificationListener => new UserCreatedNotificationListener(
$c->get(NotificationService::class),
$c->get(UserReadRepository::class),
$c->get(UserTenantRepository::class)
));
$container->set(UserDeletedNotificationListener::class, static fn (AppContainer $c): UserDeletedNotificationListener => new UserDeletedNotificationListener(
$c->get(NotificationService::class),
$c->get(UserReadRepository::class)
));
$container->set(UserActivatedNotificationListener::class, static fn (AppContainer $c): UserActivatedNotificationListener => new UserActivatedNotificationListener(
$c->get(NotificationService::class),
$c->get(UserReadRepository::class),
$c->get(UserTenantRepository::class)
));
$container->set(UserDeactivatedNotificationListener::class, static fn (AppContainer $c): UserDeactivatedNotificationListener => new UserDeactivatedNotificationListener(
$c->get(NotificationService::class),
$c->get(UserReadRepository::class),
$c->get(UserTenantRepository::class)
));
$container->set(UserAssignmentChangedNotificationListener::class, static fn (AppContainer $c): UserAssignmentChangedNotificationListener => new UserAssignmentChangedNotificationListener(
$c->get(NotificationService::class),
$c->get(UserReadRepository::class)
));
$container->set(SchedulerJobFailedNotificationListener::class, static fn (AppContainer $c): SchedulerJobFailedNotificationListener => new SchedulerJobFailedNotificationListener(
$c->get(NotificationService::class),
$c->get(UserReadRepository::class),
$c->get(UserTenantRepository::class)
));
}
}