import '../../../core/api_gateway.dart'; /// Whether the operator may retry [run], matching `canRetry` in /// `web/src/actions.js` exactly: a loaded run that is not executing and whose /// status is `failed`. A stale `failed` status while the run still executes is /// not retryable. bool canRetryRun(JsonMap? run) { if (run == null) return false; return run['executing'] != true && run['status'] == 'failed'; } /// Whether [run] can be started again with its inputs: a finished run that /// succeeded, was canceled or was interrupted, and names its pipeline. A /// failed run has Retry instead in menus (see [canStartRunAgain]). bool canRunAgain(JsonMap? run) => canStartRunAgain(run) && run!['status'] != 'failed'; /// Whether the New run form can be pre-filled from [run]: any finished run, /// failed included, that names its pipeline. A failed run's banner offers it /// beside Retry. bool canStartRunAgain(JsonMap? run) { if (run == null || run['executing'] == true) return false; final pipeline = run['pipeline_id']; return const { 'succeeded', 'failed', 'canceled', 'interrupted', }.contains(run['status']) && pipeline is num && pipeline > 0; } /// The run id used by the retry request, or null for a malformed run. num? retryRunId(JsonMap run) { final id = run['id']; return id is num ? id : null; }