Skip to content

Commit 4a4b7f3

Browse files
manskxBordatchatonawaelchli
authored
[App][CI] Delete apps older than 1 hours CI account (#15238)
Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: thomas chaton <[email protected]> Co-authored-by: Adrian Wälchli <[email protected]>
1 parent b429da9 commit 4a4b7f3

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/lightning_app/testing/testing.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import datetime
23
import json
34
import os
45
import shutil
@@ -472,6 +473,18 @@ def wait_for(page, callback: Callable, *args, **kwargs) -> Any:
472473
sleep(2)
473474

474475

476+
def _delete_lightning_app(client, project_id, app_id, app_name):
477+
print(f"Deleting {app_name} id: {app_id}")
478+
try:
479+
res = client.lightningapp_instance_service_delete_lightningapp_instance(
480+
project_id=project_id,
481+
id=app_id,
482+
)
483+
assert res == {}
484+
except ApiException as ex:
485+
print(f"Failed to delete {app_name}. Exception {ex}")
486+
487+
475488
def delete_cloud_lightning_apps():
476489
"""Cleanup cloud apps that start with the name test-{PR_NUMBER}-{TEST_APP_NAME}.
477490
@@ -492,17 +505,14 @@ def delete_cloud_lightning_apps():
492505
project = _get_project(client)
493506
list_apps = client.lightningapp_instance_service_list_lightningapp_instances(project_id=project.project_id)
494507

495-
print([lit_app.name for lit_app in list_apps.lightningapps])
496-
497508
for lit_app in list_apps.lightningapps:
498509
if pr_number and app_name and not lit_app.name.startswith(f"test-{pr_number}-{app_name}-"):
499510
continue
500-
print(f"Deleting {lit_app.name}")
501-
try:
502-
res = client.lightningapp_instance_service_delete_lightningapp_instance(
503-
project_id=project.project_id,
504-
id=lit_app.id,
505-
)
506-
assert res == {}
507-
except ApiException as e:
508-
print(f"Failed to delete {lit_app.name}. Exception {e}")
511+
_delete_lightning_app(client, project_id=project.project_id, app_id=lit_app.id, app_name=lit_app.name)
512+
513+
print("deleting apps that were created more than 1 hour ago.")
514+
515+
for lit_app in list_apps.lightningapps:
516+
517+
if lit_app.created_at < datetime.datetime.now(lit_app.created_at.tzinfo) - datetime.timedelta(hours=1):
518+
_delete_lightning_app(client, project_id=project.project_id, app_id=lit_app.id, app_name=lit_app.name)

0 commit comments

Comments
 (0)