heartbeat($source); Artisan::call('schedule:run'); } catch (Throwable $e) { Log::error('Hintergrundaufgaben fehlgeschlagen: '.$e->getMessage(), ['exception' => $e]); } finally { flock($lock, LOCK_UN); fclose($lock); } } public function heartbeat(string $source): void { $beats = $this->heartbeats(); $beats[$source] = now()->getTimestamp(); @file_put_contents(storage_path('.background-heartbeat'), json_encode($beats)); } /** * @return array Quelle (cron, webcron, pseudo) => Zeitpunkt */ public function heartbeats(): array { $data = json_decode((string) @file_get_contents(storage_path('.background-heartbeat')), true); return is_array($data) ? array_map('intval', $data) : []; } public function pseudoCronDue(): bool { $beats = $this->heartbeats(); $external = max($beats['cron'] ?? 0, $beats['webcron'] ?? 0); return now()->getTimestamp() - $external > self::PSEUDO_CRON_AFTER_SECONDS && now()->getTimestamp() - ($beats['pseudo'] ?? 0) >= 60; } public function webCronToken(): string { $token = $this->settings->get('system.cron_token'); if (! is_string($token) || strlen($token) < 32) { $token = bin2hex(random_bytes(20)); $this->settings->set('system.cron_token', $token); } return $token; } }