Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pause all service on startup #183

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from operate.account.user import UserAccount
from operate.constants import KEY, KEYS, OPERATE, SERVICES
from operate.ledger import get_ledger_type_from_chain_type
from operate.types import ChainType
from operate.types import ChainType, DeploymentStatus
from operate.wallet.master import MasterWalletManager


Expand Down Expand Up @@ -179,6 +179,25 @@ def cancel_funding_job(service: str) -> None:
if not status:
logger.info(f"Funding job cancellation for {service} failed")

def pause_all_services_on_startup():
logger.info(f"stopping services on startup")
services = [i["hash"] for i in operate.service_manager().json]

for service in services:
if not operate.service_manager().exists(service=service):
continue
deployment = operate.service_manager().create_or_load(service).deployment
if deployment.status == DeploymentStatus.DELETED:
continue
logger.info(f"stopping service {service}")
deployment.stop(force=True)
logger.info(f"Cancelling funding job for {service}")
cancel_funding_job(service=service)
logger.info(f"stopping services on startup: done")

# on backend app started we assume there are now started agents, so we force to pause all
pause_all_services_on_startup()

app = FastAPI()

app.add_middleware(
Expand Down
4 changes: 2 additions & 2 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ def start(self, use_docker: bool = False) -> None:
self.status = DeploymentStatus.DEPLOYED
self.store()

def stop(self, use_docker: bool = False) -> None:
def stop(self, use_docker: bool = False, force: bool=False) -> None:
"""Stop the deployment."""
if self.status != DeploymentStatus.DEPLOYED:
if self.status != DeploymentStatus.DEPLOYED and not force:
return

self.status = DeploymentStatus.STOPPING
Expand Down
Loading