Rollback an environment to its previous deployment.
(
self,
environment: dict,
project: Project,
db: AsyncSession,
redis_client: Redis,
settings: Settings,
)
| 566 | return deployment |
| 567 | |
| 568 | async def rollback( |
| 569 | self, |
| 570 | environment: dict, |
| 571 | project: Project, |
| 572 | db: AsyncSession, |
| 573 | redis_client: Redis, |
| 574 | settings: Settings, |
| 575 | ) -> Alias: |
| 576 | """Rollback an environment to its previous deployment.""" |
| 577 | subdomain = ( |
| 578 | project.slug |
| 579 | if environment["id"] == "prod" |
| 580 | else f"{project.slug}-env-{environment['slug']}" |
| 581 | ) |
| 582 | |
| 583 | alias = ( |
| 584 | await db.execute(select(Alias).where(Alias.subdomain == subdomain)) |
| 585 | ).scalar_one_or_none() |
| 586 | |
| 587 | if not alias or not alias.previous_deployment_id: |
| 588 | raise ValueError("No previous deployment to roll back to.") |
| 589 | |
| 590 | alias.deployment_id, alias.previous_deployment_id = ( |
| 591 | alias.previous_deployment_id, |
| 592 | alias.deployment_id, |
| 593 | ) |
| 594 | await db.commit() |
| 595 | |
| 596 | await self.update_traefik_config(project, db, settings) |
| 597 | |
| 598 | await redis_client.xadd( |
| 599 | f"stream:project:{project.id}:updates", |
| 600 | fields={ |
| 601 | "event_type": "deployment_rollback", |
| 602 | "environment_id": environment["id"], |
| 603 | "deployment_id": alias.deployment_id, |
| 604 | "previous_deployment_id": alias.previous_deployment_id or "", |
| 605 | "timestamp": datetime.now(timezone.utc).isoformat(), |
| 606 | }, |
| 607 | ) |
| 608 | |
| 609 | return alias |
| 610 | |
| 611 | # async def promote( |
| 612 | # self, |
no test coverage detected