Skip to content

Commit

Permalink
[Chore] Nightly cleanup handles deletion_protection
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Nov 15, 2024
1 parent 0004eed commit 98a3f79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cleanup-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
cleanup-all:
name: Cleanupu all indexes/collections
name: Cleanup all indexes/collections
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
cleanup-all:
name: Cleanupu all indexes/collections
name: Cleanup all indexes/collections
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
71 changes: 35 additions & 36 deletions scripts/cleanup-all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@
import time


def delete_index(pc, index_name):
try:
print("Deleting index: " + index_name)
desc = pc.describe_index(index_name)

# Check whether index can be deleted
if desc.deletion_protection == "enabled":
pc.configure_index(index_name, deletion_protection="disabled")

# Wait for index to be ready before deleting
ready_to_delete = False
max_wait = 60
time_waited = 0
while not ready_to_delete:
desc = pc.describe_index(index_name)
if desc.status.state == "Ready":
ready_to_delete = True
break
else:
print("Index is not ready yet. Waiting for 2 seconds.")
time.sleep(2)
time_waited += 2

if time_waited > max_wait:
print(f"Timed out waiting for index {index_name} to be ready")
break

pc.delete_index(index_name)
except Exception as e:
print("Failed to delete index: " + index_name + " " + str(e))
pass


def delete_everything(pc):
for collection in pc.list_collections().names():
try:
Expand All @@ -15,36 +48,7 @@ def delete_everything(pc):
pass

for index in pc.list_indexes().names():
try:
print("Deleting index: " + index)
desc = pc.describe_index(index)

# Check whether index can be deleted
if desc.deletion_protection == "enabled":
pc.configure_index(index, deletion_protection="disabled")

# Wait for index to be ready before deleting
ready_to_delete = False
max_wait = 60
time_waited = 0
while not ready_to_delete:
desc = pc.describe_index(index)
if desc.status.state == "Ready":
ready_to_delete = True
break
else:
print("Index is not ready yet. Waiting for 2 seconds.")
time.sleep(2)
time_waited += 2

if time_waited > max_wait:
print(f"Timed out waiting for index {index} to be ready")
break

pc.delete_index(index)
except Exception as e:
print("Failed to delete index: " + index + " " + str(e))
pass
delete_index(pc, index)


def parse_date(resource_name):
Expand Down Expand Up @@ -86,12 +90,7 @@ def delete_old(pc):

for index in pc.list_indexes().names():
if is_resource_old(index):
try:
print("Deleting index: " + index)
pc.delete_index(index)
except Exception as e:
print("Failed to delete index: " + index + " " + str(e))
pass
delete_index(pc, index)
else:
print("Skipping index, not old enough: " + index)

Expand Down

0 comments on commit 98a3f79

Please sign in to comment.