-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from NASA-IMPACT/candidate-url-model-modeific…
…ation Health check on urls and titles from test and production servers
- Loading branch information
Showing
9 changed files
with
1,486 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,290 changes: 1,290 additions & 0 deletions
1,290
jupyter_notebooks/health_check_on_urls_titles.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from sde_collections.models.candidate_url import CandidateURL | ||
from sde_collections.models.collection import Collection | ||
from sde_collections.sinequa_api import Api | ||
|
||
|
||
def _health_check_on_urls_titles(server_name: str): | ||
if server_name == "test": | ||
url_field = "download_url" | ||
status_field = "present_on_test" | ||
title_field = "test_title" | ||
elif server_name == "production": | ||
url_field = "url1" | ||
status_field = "present_on_prod" | ||
title_field = "production_title" | ||
else: | ||
# Handle invalid server name | ||
raise ValueError(f"Invalid server name: {server_name}") | ||
|
||
api = Api(server_name=server_name) | ||
|
||
collection_config_folders = [ | ||
collection.config_folder for collection in Collection.objects.all() | ||
] | ||
|
||
for collection_config_folder in collection_config_folders: | ||
page = 1 | ||
urls_server_info_dict = {} | ||
while True: | ||
response = api.query( | ||
page=page, collection_config_folder=collection_config_folder | ||
) | ||
if ( | ||
response.get("cursorRowCount", 0) == 0 | ||
): # Safeguard against missing 'cursorRowCount' | ||
break | ||
for record in response.get( | ||
"records", [] | ||
): # Safeguard against missing 'records' | ||
url = record.get(url_field) | ||
title = record.get("title") | ||
if url and title: # Ensure both url and title are present | ||
urls_server_info_dict[url] = {"title": title} | ||
page += 1 | ||
print( | ||
f"Finished collecting URLs from {server_name} server for config folder {collection_config_folder}" | ||
) | ||
|
||
collection_object = Collection.objects.filter( | ||
config_folder=collection_config_folder | ||
) | ||
candidate_urls_objects = CandidateURL.objects.filter( | ||
collection=collection_object[0] | ||
) | ||
for candidate_urls_object in candidate_urls_objects: | ||
is_present_on_server = ( | ||
candidate_urls_object.url in urls_server_info_dict.keys() | ||
) | ||
if getattr(candidate_urls_object, status_field) != is_present_on_server: | ||
setattr(candidate_urls_object, status_field, is_present_on_server) | ||
try: | ||
setattr( | ||
candidate_urls_object, | ||
title_field, | ||
urls_server_info_dict.get(candidate_urls_object.url)["title"], | ||
) | ||
except TypeError: | ||
setattr(candidate_urls_object, title_field, "Unavailable") | ||
candidate_urls_object.save() | ||
print( | ||
f"Finished updating urls within collection config folder {collection_config_folder}" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
_health_check_on_urls_titles(server_name="test") | ||
_health_check_on_urls_titles(server_name="production") |
50 changes: 50 additions & 0 deletions
50
sde_collections/migrations/0036_candidateurl_present_on_prod_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 4.2.6 on 2023-10-25 14:50 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("sde_collections", "0035_alter_candidateurl_unique_together"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="candidateurl", | ||
name="present_on_prod", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="Helps keep track if the Current URL is present in production or not", | ||
verbose_name="URL Present In Production?", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="candidateurl", | ||
name="present_on_test", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="Helps keep track if the Current URL is present in test environment or not", | ||
verbose_name="URL Present In Test Environment?", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="candidateurl", | ||
name="production_title", | ||
field=models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="This is the title present on Production Server", | ||
verbose_name="Title on Production Server", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="candidateurl", | ||
name="test_title", | ||
field=models.CharField( | ||
blank=True, | ||
default="", | ||
help_text="This is the title present on Test Server", | ||
verbose_name="Title on Test Server", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters