Skip to content

Commit 11a366f

Browse files
authored
Merge pull request #1125 from NASA-IMPACT/1055-add-additional-workflow-statuses-on-cosmos-to-help-the-re-indexation-process
add initial reindexing statuses
2 parents b001d04 + 04ba82c commit 11a366f

File tree

9 files changed

+613
-118
lines changed

9 files changed

+613
-118
lines changed

sde_collections/admin.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
)
1212

1313
from .models.candidate_url import CandidateURL, ResolvedTitle
14-
from .models.collection import Collection, WorkflowHistory
14+
from .models.collection import Collection, ReindexingHistory, WorkflowHistory
1515
from .models.collection_choice_fields import TDAMMTags
1616
from .models.delta_url import CuratedUrl, DeltaUrl, DumpUrl
1717
from .models.pattern import DivisionPattern, IncludePattern, TitlePattern
@@ -217,6 +217,7 @@ class CollectionAdmin(admin.ModelAdmin, ExportCsvMixin, UpdateConfigMixin):
217217
"source",
218218
"turned_on",
219219
"is_multi_division",
220+
"reindexing_status",
220221
),
221222
},
222223
),
@@ -250,10 +251,18 @@ class CollectionAdmin(admin.ModelAdmin, ExportCsvMixin, UpdateConfigMixin):
250251
"division",
251252
"new_collection",
252253
"is_multi_division",
254+
"reindexing_status",
253255
)
254256

255257
readonly_fields = ("config_folder",)
256-
list_filter = ("division", "curation_status", "workflow_status", "turned_on", "is_multi_division")
258+
list_filter = (
259+
"division",
260+
"curation_status",
261+
"workflow_status",
262+
"turned_on",
263+
"is_multi_division",
264+
"reindexing_status",
265+
)
257266
search_fields = ("name", "url", "config_folder")
258267
actions = [
259268
generate_deployment_message,
@@ -392,6 +401,12 @@ class WorkflowHistoryAdmin(admin.ModelAdmin):
392401
list_filter = ["workflow_status", "old_status"]
393402

394403

404+
class ReindexingHistoryAdmin(admin.ModelAdmin):
405+
list_display = ("collection", "old_status", "reindexing_status", "created_at")
406+
search_fields = ["collection__name"]
407+
list_filter = ["reindexing_status", "old_status"]
408+
409+
395410
class ResolvedTitleAdmin(admin.ModelAdmin):
396411
list_display = ["title_pattern", "candidate_url", "resolved_title", "created_at"]
397412

@@ -449,6 +464,7 @@ class CuratedUrlAdmin(TDAMMAdminMixin, admin.ModelAdmin):
449464
form = CuratedURLForm
450465

451466

467+
admin.site.register(ReindexingHistory, ReindexingHistoryAdmin)
452468
admin.site.register(WorkflowHistory, WorkflowHistoryAdmin)
453469
admin.site.register(CandidateURL, CandidateURLAdmin)
454470
admin.site.register(TitlePattern, TitlePatternAdmin)
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Generated by Django 4.2.9 on 2024-12-06 03:51
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
7+
8+
def set_initial_reindexing_status(apps, schema_editor):
9+
Collection = apps.get_model("sde_collections", "Collection")
10+
11+
# List of collections that have been reindexed on LRM dev
12+
reindexed_collections = {
13+
"astrophysics_source_code_library",
14+
"astrophysics_science_division_asd_code_660",
15+
"the_astrophysics_astrochemistry_lab",
16+
"Space_Physics_Data_Facility",
17+
"ppi_node",
18+
"sun_climate_powered_by_solar_irradiance",
19+
"magnetospheric_multiscale_satellites",
20+
"mdscc_deep_space_network",
21+
"voyager",
22+
"f_prime",
23+
"interactive_multiinstrument_database_of_solar_flares",
24+
"cii_hosted_payload_opportunity_online_database",
25+
"national_space_weather_program",
26+
"starchild_a_learning_center_for_young_astronomers",
27+
"nexsci",
28+
"explorer_1",
29+
"the_new_great_observatories",
30+
"nasa_ames_intelligent_systems_division_data",
31+
"tropical_cyclone_information_system_data_repository",
32+
"explorers_and_heliophysics_projects_division",
33+
}
34+
35+
# Define the workflow status values
36+
RESEARCH_IN_PROGRESS = 1
37+
READY_FOR_ENGINEERING = 2
38+
ENGINEERING_IN_PROGRESS = 3
39+
READY_FOR_CURATION = 4
40+
CURATION_IN_PROGRESS = 5
41+
CURATED = 6
42+
QUALITY_FIXED = 7
43+
SECRET_DEPLOYMENT_STARTED = 8
44+
SECRET_DEPLOYMENT_FAILED = 9
45+
READY_FOR_LRM_QUALITY_CHECK = 10
46+
READY_FOR_FINAL_QUALITY_CHECK = 11
47+
QUALITY_CHECK_FAILED = 12
48+
QUALITY_CHECK_PERFECT = 13
49+
MERGE_PENDING = 14
50+
NEEDS_DELETE = 19
51+
52+
# Workflow statuses that should be marked as reindexing not needed
53+
reindexing_not_needed_statuses = [
54+
RESEARCH_IN_PROGRESS,
55+
READY_FOR_ENGINEERING,
56+
ENGINEERING_IN_PROGRESS,
57+
READY_FOR_CURATION,
58+
CURATION_IN_PROGRESS,
59+
CURATED,
60+
QUALITY_FIXED,
61+
SECRET_DEPLOYMENT_STARTED,
62+
SECRET_DEPLOYMENT_FAILED,
63+
READY_FOR_LRM_QUALITY_CHECK,
64+
READY_FOR_FINAL_QUALITY_CHECK,
65+
QUALITY_CHECK_FAILED,
66+
QUALITY_CHECK_PERFECT,
67+
MERGE_PENDING,
68+
NEEDS_DELETE,
69+
]
70+
71+
# Set collections that have been reindexed
72+
Collection.objects.filter(config_folder__in=reindexed_collections).update(reindexing_status=3) # FINISHED
73+
74+
# Set collections that don't need reindexing
75+
Collection.objects.filter(workflow_status__in=reindexing_not_needed_statuses).exclude(
76+
config_folder__in=reindexed_collections
77+
).update(
78+
reindexing_status=1
79+
) # NOT_NEEDED
80+
81+
# All other collections need reindexing
82+
Collection.objects.exclude(config_folder__in=reindexed_collections).exclude(
83+
workflow_status__in=reindexing_not_needed_statuses
84+
).update(
85+
reindexing_status=2
86+
) # NEEDED
87+
88+
89+
class Migration(migrations.Migration):
90+
91+
dependencies = [
92+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
93+
("sde_collections", "0071_alter_candidateurl_tdamm_tag_manual_and_more"),
94+
]
95+
96+
operations = [
97+
migrations.AddField(
98+
model_name="collection",
99+
name="reindexing_status",
100+
field=models.IntegerField(
101+
choices=[
102+
(1, "Reindexing Not Needed"),
103+
(2, "Reindexing Needed on LRM Dev"),
104+
(3, "Reindexing Finished on LRM Dev"),
105+
(4, "Ready for Curation"),
106+
(5, "Curated"),
107+
(6, "Indexed on Prod"),
108+
],
109+
default=1,
110+
verbose_name="Reindexing Status",
111+
),
112+
),
113+
migrations.CreateModel(
114+
name="ReindexingHistory",
115+
fields=[
116+
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
117+
(
118+
"reindexing_status",
119+
models.IntegerField(
120+
choices=[
121+
(1, "Reindexing Not Needed"),
122+
(2, "Reindexing Needed on LRM Dev"),
123+
(3, "Reindexing Finished on LRM Dev"),
124+
(4, "Ready for Curation"),
125+
(5, "Curated"),
126+
(6, "Indexed on Prod"),
127+
],
128+
default=1,
129+
),
130+
),
131+
(
132+
"old_status",
133+
models.IntegerField(
134+
choices=[
135+
(1, "Reindexing Not Needed"),
136+
(2, "Reindexing Needed on LRM Dev"),
137+
(3, "Reindexing Finished on LRM Dev"),
138+
(4, "Ready for Curation"),
139+
(5, "Curated"),
140+
(6, "Indexed on Prod"),
141+
],
142+
null=True,
143+
),
144+
),
145+
("created_at", models.DateTimeField(auto_now_add=True)),
146+
(
147+
"collection",
148+
models.ForeignKey(
149+
null=True,
150+
on_delete=django.db.models.deletion.CASCADE,
151+
related_name="reindexing_history",
152+
to="sde_collections.collection",
153+
),
154+
),
155+
(
156+
"curated_by",
157+
models.ForeignKey(
158+
blank=True,
159+
null=True,
160+
on_delete=django.db.models.deletion.DO_NOTHING,
161+
to=settings.AUTH_USER_MODEL,
162+
),
163+
),
164+
],
165+
),
166+
migrations.RunPython(set_initial_reindexing_status),
167+
]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Reindexing Status Documentation
2+
3+
### Reindexing Not Needed
4+
- Variable name: `REINDEXING_NOT_NEEDED` (1)
5+
- Default status for new collections
6+
- Applied to collections in early workflow stages (research, engineering, etc.)
7+
8+
### Reindexing Needed on LRM Dev
9+
- Variable name: `REINDEXING_NEEDED_ON_DEV` (2)
10+
- Indicates collections that need to be reindexed on LRM Dev environment
11+
- For collections that have already been indexed on production
12+
13+
### Reindexing Finished on LRM Dev
14+
- Variable name: `REINDEXING_FINISHED_ON_DEV` (3)
15+
- For collections that have completed reindexing on LRM Dev
16+
- Currently managed manually by LRM team via admin interface
17+
18+
### Ready for Curation
19+
- Variable name: `REINDEXING_READY_FOR_CURATION` (4)
20+
- Automatically set when:
21+
- A collection's dump URLs are migrated to delta URLs AND there are curated URLs present
22+
- Triggered by Collection.migrate_dump_to_delta() method
23+
24+
### Curated
25+
- Variable name: `REINDEXING_CURATED` (5)
26+
- Automatically set when:
27+
- Delta URLs are promoted to curated URLs AND there are curated URLs present
28+
- Triggered by Collection.promote_to_curated() method
29+
30+
### Indexed on Prod
31+
- Variable name: `REINDEXING_INDEXED_ON_PROD` (6)
32+
- Currently managed manually via command line
33+
- Future: Will be set automatically via plugin ping
34+
35+
### Key Code Locations for Automatic Changes
36+
37+
1. In migrate_dump_to_delta():
38+
```python
39+
# After migrating, check if we should update reindexing status
40+
curated_urls_count = self.curated_urls.count()
41+
if curated_urls_count > 0:
42+
self.reindexing_status = ReindexingStatusChoices.REINDEXING_READY_FOR_CURATION
43+
self.save()
44+
```
45+
46+
2. In promote_to_curated():
47+
```python
48+
# After promoting, check if we should update reindexing status
49+
curated_urls_count = self.curated_urls.count()
50+
if curated_urls_count > 0:
51+
self.reindexing_status = ReindexingStatusChoices.REINDEXING_CURATED
52+
self.save()
53+
```
54+
55+
Note: All status changes are logged in the ReindexingHistory model for tracking purposes.

sde_collections/models/collection.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
CurationStatusChoices,
2424
Divisions,
2525
DocumentTypes,
26+
ReindexingStatusChoices,
2627
SourceChoices,
2728
UpdateFrequencies,
2829
WorkflowStatusChoices,
@@ -75,6 +76,11 @@ class Collection(models.Model):
7576
choices=WorkflowStatusChoices.choices,
7677
default=WorkflowStatusChoices.RESEARCH_IN_PROGRESS,
7778
)
79+
reindexing_status = models.IntegerField(
80+
choices=ReindexingStatusChoices.choices,
81+
default=ReindexingStatusChoices.REINDEXING_NOT_NEEDED,
82+
verbose_name="Reindexing Status",
83+
)
7884
tracker = FieldTracker(fields=["workflow_status"])
7985

8086
curated_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True, blank=True)
@@ -155,6 +161,12 @@ def migrate_dump_to_delta(self):
155161
# self.refresh_url_lists_for_all_patterns() # TODO: I'm pretty confident we shouldn't be running this
156162
self.apply_all_patterns()
157163

164+
# After migrating, check if we should update reindexing status
165+
curated_urls_count = self.curated_urls.count()
166+
if curated_urls_count > 0:
167+
self.reindexing_status = ReindexingStatusChoices.REINDEXING_READY_FOR_CURATION
168+
self.save()
169+
158170
def create_or_update_delta_url(self, url_instance, to_delete=False):
159171
"""
160172
Creates or updates a DeltaUrl entry based on the given DumpUrl or CuratedUrl object.
@@ -224,6 +236,12 @@ def promote_to_curated(self):
224236
# Step 4: Reapply patterns to DeltaUrls
225237
self.refresh_url_lists_for_all_patterns()
226238

239+
# After promoting, check if we should update reindexing status
240+
curated_urls_count = self.curated_urls.count()
241+
if curated_urls_count > 0:
242+
self.reindexing_status = ReindexingStatusChoices.REINDEXING_CURATED
243+
self.save()
244+
227245
def add_to_public_query(self):
228246
"""Add the collection to the public query."""
229247
if self.workflow_status not in [
@@ -349,6 +367,18 @@ def workflow_status_button_color(self) -> str:
349367
}
350368
return color_choices[self.workflow_status]
351369

370+
@property
371+
def reindexing_status_button_color(self) -> str:
372+
color_choices = {
373+
1: "btn-light", # NOT_NEEDED
374+
2: "btn-warning", # NEEDED
375+
3: "btn-secondary", # FINISHED
376+
4: "btn-info", # READY_FOR_CURATION
377+
5: "btn-primary", # CURATED
378+
6: "btn-success", # INDEXED_ON_PROD
379+
}
380+
return color_choices[self.reindexing_status]
381+
352382
def _process_exclude_list(self):
353383
"""Process the exclude list."""
354384
return [pattern._process_match_pattern() for pattern in self.excludepattern.all()]
@@ -654,6 +684,7 @@ def __init__(self, *args, **kwargs):
654684
# Create a cached version of the last workflow_status to compare against
655685
super().__init__(*args, **kwargs)
656686
self.old_workflow_status = self.workflow_status
687+
self.old_reindexing_status = self.reindexing_status
657688

658689

659690
class RequiredUrls(models.Model):
@@ -734,6 +765,40 @@ def log_workflow_history(sender, instance, created, **kwargs):
734765
old_status=instance.old_workflow_status,
735766
)
736767

768+
if instance.reindexing_status != instance.old_reindexing_status:
769+
ReindexingHistory.objects.create(
770+
collection=instance,
771+
reindexing_status=instance.reindexing_status,
772+
curated_by=instance.curated_by,
773+
old_status=instance.old_reindexing_status,
774+
)
775+
776+
777+
class ReindexingHistory(models.Model):
778+
collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name="reindexing_history", null=True)
779+
reindexing_status = models.IntegerField(
780+
choices=ReindexingStatusChoices.choices,
781+
default=ReindexingStatusChoices.REINDEXING_NOT_NEEDED,
782+
)
783+
old_status = models.IntegerField(choices=ReindexingStatusChoices.choices, null=True)
784+
curated_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True, blank=True)
785+
created_at = models.DateTimeField(auto_now_add=True)
786+
787+
def __str__(self):
788+
return str(self.collection) + str(self.reindexing_status)
789+
790+
@property
791+
def reindexing_status_button_color(self) -> str:
792+
color_choices = {
793+
1: "btn-light", # REINDEXING_NOT_NEEDED
794+
2: "btn-warning", # REINDEXING_NEEDED_ON_DEV
795+
3: "btn-secondary", # REINDEXING_FINISHED_ON_DEV
796+
4: "btn-info", # REINDEXING_READY_FOR_CURATION
797+
5: "btn-primary", # REINDEXING_CURATED
798+
6: "btn-success", # REINDEXING_INDEXED_ON_PROD
799+
}
800+
return color_choices[self.reindexing_status]
801+
737802

738803
@receiver(post_save, sender=Collection)
739804
def create_configs_on_status_change(sender, instance, created, **kwargs):

0 commit comments

Comments
 (0)