call('upstream:schema:sync', ['--due' => true]); $storeName = (string) config('upstreams.snapshots.cache_store', 'upstream_shared'); $cache = $cacheManager->store($storeName); $failed = false; foreach ($refreshers->sources() as $source) { $lock = $cache->lock('refresh-cycle:' . $source, 180); if (! $lock->get()) { continue; } try { $arguments = ['source' => $source]; if ($this->option('limit') !== null) { $arguments['--limit'] = (int) $this->option('limit'); } if ($this->call('upstream:snapshots:refresh', $arguments) !== self::SUCCESS) { $failed = true; } } catch (Throwable $exception) { $failed = true; Log::error('上游共享快照刷新周期失败,已继续处理其他来源。', [ 'source' => $source, 'exception' => $exception::class, ]); } finally { $lock->release(); } } $this->pruneExpiredSharedEntries($cache, $storeName); return $failed ? self::FAILURE : self::SUCCESS; } private function pruneExpiredSharedEntries(Repository $cache, string $storeName): void { $window = now()->format('YmdH'); if (! $cache->add('prune-window:' . $window, true, 7200)) { return; } $store = (array) config('cache.stores.' . $storeName, []); if (($store['driver'] ?? null) !== 'database') { return; } try { $connection = DB::connection($store['connection'] ?? null); $expiration = time(); $connection->table((string) ($store['table'] ?? 'upstream_query_cache')) ->where('expiration', '<=', $expiration) ->delete(); $connection->table((string) ($store['lock_table'] ?? 'upstream_query_locks')) ->where('expiration', '<=', $expiration) ->delete(); } catch (Throwable $exception) { Log::warning('清理过期上游共享快照失败。', [ 'exception' => $exception::class, ]); } } }