|
import os |
|
from pymilvus import connections |
|
from pymilvus import Collection |
|
from datetime import date |
|
import logging |
|
|
|
|
|
def get_min_age_to_delete(): |
|
BASE_DATE = date(2024, 1, 1) |
|
today = date.today() |
|
timedelta = today - BASE_DATE |
|
return timedelta.days - 30 |
|
|
|
|
|
def get_secrets(): |
|
uri = os.environ.get("URI") |
|
token = os.environ.get("TOKEN") |
|
collection_name = os.environ.get("COLLECTION_NAME") |
|
return uri, token, collection_name |
|
|
|
|
|
def get_collection(uri: str, token: str, collection_name: str): |
|
connections.connect("default", uri=uri, token=token) |
|
collection = Collection(name=collection_name) |
|
print("Loaded existing collection") |
|
return collection |
|
|
|
def delete_from_db(): |
|
uri, token, collection_name = get_secrets() |
|
collection = get_collection(uri, token, collection_name) |
|
min_age_to_delete = get_min_age_to_delete() |
|
expr = f"article_age <= {min_age_to_delete}" |
|
collection.delete(expr) |
|
logging.warning('Successfully deleted older articles') |
|
res = collection.query(expr="article_age > -1000", output_fields = ["article_age"]) |
|
|
|
|
|
|
|
|