fetchSnapshot static method
Fetches the status, deployments, metrics and recent logs of projectId.
Throws a FailureException if the status cannot be fetched. Deployments, metrics and logs that cannot be fetched are null in the snapshot instead, so one missing panel does not block the others.
Implementation
static Future<TopSnapshot> fetchSnapshot(
final Client cloudApiClient, {
required final String projectId,
required final int deploymentLimit,
required final int logLimit,
}) async {
final CapsuleRuntimeStatus runtime =
await StatusCommands.fetchRuntimeStatus(
cloudApiClient,
projectId: projectId,
);
final DateTime now = DateTime.now();
final (
List<DeployAttempt>? deployments,
_Metrics metrics,
List<LogRecord>? logs,
) = await (
_fetchDeployments(
cloudApiClient,
projectId: projectId,
limit: deploymentLimit,
),
_fetchMetrics(cloudApiClient, projectId: projectId, until: now),
_orNull(() {
return cloudApiClient.logs
.fetchRecentRecords(cloudCapsuleId: projectId, limit: logLimit)
.toList();
}),
).wait;
return TopSnapshot(
runtime: runtime,
updatedAt: now,
deployments: deployments,
podResources: metrics.podResources,
network: metrics.network,
database: metrics.database,
metricsUntil: now,
logs: logs,
);
}