execute static method
Future<bool>
execute(
- DVRollbackPlan plan, {
- required DVReleaseAdapter adapter,
- required DVReleaseHistory history,
- required DateTime now,
Routes all traffic to the plan's target, confirms the platform reports
it, and records the rollback in history.
Returns false, and records nothing, when the platform does not report the target at all traffic. Throws when the plan is refused or was made against a history that has since moved.
Implementation
static Future<bool> execute(
DVRollbackPlan plan, {
required DVReleaseAdapter adapter,
required DVReleaseHistory history,
required DateTime now,
}) async {
if (!plan.allowed) {
throw StateError(
'the rollback is refused: ${plan.refusals.join('; ')}',
);
}
if (!identical(history.current, plan.from)) {
throw StateError(
'the plan was made while ${plan.from!.id} was serving and '
'${history.current?.id} is serving now; plan again',
);
}
final DVDeployedRelease to = plan.to!;
await adapter.route(candidate: to.id, previous: plan.from!.id, percent: 100);
if (await adapter.weightOf(to.id) != 100) return false;
history.rolledBack(to: to.id, at: now);
return true;
}