Skip to content

Commit

Permalink
Merge pull request #3418 from bcgov/feat/3369
Browse files Browse the repository at this point in the history
chore(3077): skip temporary products with an active request
  • Loading branch information
junminahn authored Jul 25, 2024
2 parents 4a538cb + 03ab1d8 commit c2742f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/components/form/TemporaryProductCheckboxAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function TemporaryProductCheckboxAdmin({
if (formState.dirtyFields.isTest) {
updateFlag(isTest);
}
}, [formState.dirtyFields.isTest]);
}, [updateFlag, formState.dirtyFields.isTest, isTest]);

return (
<Alert variant="light" color="blue" title="Temporary product set" className={classNames(className)}>
Expand All @@ -62,8 +62,8 @@ export default function TemporaryProductCheckboxAdmin({
disabled={disabled}
className={{ label: 'text-lg', input: 'ml-1' }}
showConfirm
confirmCheckedTitle="Are you sure you want to set this product as a permanent product set?"
confirmUncheckedTitle="Are you sure you want to set this product as a temporary product set?"
confirmCheckedTitle="Are you sure you want to set this product as a temporary product set?"
confirmUncheckedTitle="Are you sure you want to set this product as a permanent product set?"
confirmCheckedMessage="You have selected a temporary product set. Please be aware that everything in the provisioned namespaces will be deleted after 30 days, including all data and deployments."
confirmUncheckedMessage="You have unchecked a temporary product set. Please be aware that product set will NOT be deleted after 30 days."
>
Expand Down
18 changes: 14 additions & 4 deletions helm/tools/dags/_temporary_products_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def send_temp_products_deletion_request(

thirty_days_ago = datetime.now(timezone.utc) - timedelta(days=30)
query = {"isTest": True, "status": "ACTIVE", "createdAt": {"$lt": thirty_days_ago}}
print(f"Querying {query}...")
projection = {"_id": False, "licencePlate": True}
projects = db.PrivateCloudProject.find(query, projection=projection)

Expand All @@ -21,11 +22,20 @@ def send_temp_products_deletion_request(

count = 0
for project in projects:
count += 1
licence_plate = project.get("licencePlate")
print(f"Processing {licence_plate}...")
url = product_deletion_url_template.format(licence_plate)
response = requests.delete(url, headers=headers)
response.raise_for_status()

reqQuery = {"licencePlate": licence_plate, "active": True}
reqProjection = {"_id": True}
activeReq = db.PrivateCloudRequest.find_one(reqQuery, projection=reqProjection)

if activeReq is None:
count += 1
url = product_deletion_url_template.format(licence_plate)
print(f"Sending a request to {url}")
response = requests.delete(url, headers=headers)
response.raise_for_status()
else:
print(f"Has an active request; skipping...")

return {"status": "success", "count": count}

0 comments on commit c2742f5

Please sign in to comment.