Skip to content
Merged
Changes from all 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
32 changes: 21 additions & 11 deletions src/lightning_app/testing/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import datetime
import json
import os
import shutil
Expand Down Expand Up @@ -472,6 +473,18 @@ def wait_for(page, callback: Callable, *args, **kwargs) -> Any:
sleep(2)


def _delete_lightning_app(client, project_id, app_id, app_name):
print(f"Deleting {app_name} id: {app_id}")
try:
res = client.lightningapp_instance_service_delete_lightningapp_instance(
project_id=project_id,
id=app_id,
)
assert res == {}
except ApiException as ex:
print(f"Failed to delete {app_name}. Exception {ex}")


def delete_cloud_lightning_apps():
"""Cleanup cloud apps that start with the name test-{PR_NUMBER}-{TEST_APP_NAME}.

Expand All @@ -492,17 +505,14 @@ def delete_cloud_lightning_apps():
project = _get_project(client)
list_apps = client.lightningapp_instance_service_list_lightningapp_instances(project_id=project.project_id)

print([lit_app.name for lit_app in list_apps.lightningapps])

for lit_app in list_apps.lightningapps:
if pr_number and app_name and not lit_app.name.startswith(f"test-{pr_number}-{app_name}-"):
continue
print(f"Deleting {lit_app.name}")
try:
res = client.lightningapp_instance_service_delete_lightningapp_instance(
project_id=project.project_id,
id=lit_app.id,
)
assert res == {}
except ApiException as e:
print(f"Failed to delete {lit_app.name}. Exception {e}")
_delete_lightning_app(client, project_id=project.project_id, app_id=lit_app.id, app_name=lit_app.name)

print("deleting apps that were created more than 1 hour ago.")

for lit_app in list_apps.lightningapps:

if lit_app.created_at < datetime.datetime.now(lit_app.created_at.tzinfo) - datetime.timedelta(hours=1):
_delete_lightning_app(client, project_id=project.project_id, app_id=lit_app.id, app_name=lit_app.name)