How to customise completed export notification/events?

I want to change the way I receive the completed export notification, or add to it. I want to either broadcast the notification in real time, or send the completed export notification to the UI as well as to the database.

I know I can control this fully in the ExportCompletion.php jobs handle method:
class ExportCompletion implements ShouldQueue
{
  // Truncated

  public function handle(): void
  {
    $this->export->touch('completed_at');

    if (! $this->export->user instanceof Authenticatable) {
      return;
    }

    $failedRowsCount = $this->export->getFailedRowsCount();

    Notification::make()
      ->title(__('filament-actions::export.notifications.completed.title'))
      ->body($this->exporter::getCompletedNotificationBody($this->export))
      ->when(
        ! $failedRowsCount,
        fn (Notification $notification) => $notification->success(),
      )
      ->when(
        $failedRowsCount && ($failedRowsCount < $this->export->total_rows),
        fn (Notification $notification) => $notification->warning(),
      )
      ->when(
        $failedRowsCount === $this->export->total_rows,
        fn (Notification $notification) => $notification->danger(),
      )
      ->when(
        $failedRowsCount < $this->export->total_rows,
        fn (Notification $notification) => $notification->actions(array_map(
          fn (ExportFormat $format): NotificationAction => $format->getDownloadNotificationAction($this->export),
          $this->formats,
        )),
      )
->sendToDatabase($this->export->user);
  }
}

I hear that overriding files like filament/packages/actions/src/Exports/Jobs/ExportCompletion.php is not advised. So what is the best way to customise what happens when an export job completes?

Any help is much appreciated!
Was this page helpful?