clock->now(); return $this->transactions->run(function () use ($now): int { $added = 0; foreach ($this->maintenance->due() as $item) { if ($item->responsibleUserId === null) { continue; } $notification = NewNotification::maintenanceDue($item->responsibleUserId, $item->id, $item->lastRecordId, $item->level->value, [ 'machine_id' => $item->machineId, 'machine' => $item->machineName, 'item' => $item->name, 'level' => $item->level->value, ], $now); if ($this->notifications->addIfNew($notification)) { $added++; } } return $added; }); } }