Skip to content

Commit 7140f51

Browse files
author
Your Name
committed
Fixes issue #1014
1 parent 2f18832 commit 7140f51

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

sde_collections/models/collection.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,22 @@ def apply_all_patterns(self):
634634
for pattern in self.deltadivisionpatterns.all():
635635
pattern.apply()
636636

637+
def count_curated_urls(self):
638+
"""Return the count of Curated URLs for the collection."""
639+
return CuratedUrl.objects.filter(collection=self).count()
640+
641+
def count_dump_urls(self):
642+
"""Return the count of all Dump URLs for the collection."""
643+
return DumpUrl.objects.filter(collection=self).count()
644+
645+
def count_delta_urls(self):
646+
"""Return the count of Delta URLs identified."""
647+
return DeltaUrl.objects.filter(collection=self).count()
648+
649+
def count_marked_for_deletion_urls(self):
650+
"""Return the count of Delta URLs marked for deletion."""
651+
return DeltaUrl.objects.filter(collection=self, to_delete=True).count()
652+
637653
def save(self, *args, **kwargs):
638654
# Call the function to generate the value for the generated_field based on the original_field
639655
if not self.config_folder:

sde_collections/tasks.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import json
22
import os
33
import shutil
4-
54
import boto3
65
from django.apps import apps
76
from django.conf import settings
87
from django.core import management
98
from django.core.management.commands import loaddata
109
from django.db import transaction
11-
10+
from sde_collections.utils import slack_utils
1211
from config import celery_app
1312
from sde_collections.models.collection_choice_fields import (
1413
ReindexingStatusChoices,
@@ -215,6 +214,14 @@ def fetch_and_replace_full_text(collection_id, server_name):
215214
collection.reindexing_status = ReindexingStatusChoices.REINDEXING_READY_FOR_CURATION
216215
collection.save()
217216

217+
curated_count = collection.count_curated_urls()
218+
dump_count = collection.count_dump_urls()
219+
delta_count = collection.count_delta_urls()
220+
deletion_count = collection.count_marked_for_deletion_urls()
221+
222+
slack_utils.send_detailed_import_notification(
223+
collection.name, total_processed, curated_count, dump_count, delta_count, deletion_count
224+
)
218225
return f"Successfully processed {total_processed} records and updated the database."
219226

220227
except Exception as e:

sde_collections/utils/slack_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ def format_slack_message(name, details, collection_id):
5858
return slack_mentions + " " + message_template.format(name=linked_name)
5959
return message_template.format(name=linked_name)
6060

61+
def send_detailed_import_notification(collection_name, total_processed, curated_count, dump_count, delta_count, deletion_count):
62+
message = (f"'{collection_name}' brought into COSMOS. "
63+
f"Prior Curated: {curated_count}, URL counts - [Server: {total_processed}, "
64+
f"Dump: {dump_count}, New Deltas: {delta_count}, Deleted: {deletion_count}]")
65+
66+
webhook_url = settings.SLACK_WEBHOOK_URL
67+
payload = {"text": message}
68+
response = requests.post(webhook_url, json=payload)
69+
if response.status_code != 200:
70+
print(f"Error sending Slack message: {response.text}")
6171

6272
def send_slack_message(message):
6373
webhook_url = settings.SLACK_WEBHOOK_URL

0 commit comments

Comments
 (0)