Skip to content

Commit 1689b88

Browse files
authored
fix: Wire bcp, std, fyi index creation (#10706)
* style: Ruff Ruff * fix: Wire bcp and std index creation tasks * fix: Use single task and add fyi index creation * fix: Log index creation errors and continue
1 parent 60ecfa2 commit 1689b88

2 files changed

Lines changed: 72 additions & 31 deletions

File tree

ietf/api/views_rpc.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
EmailPersonSerializer,
3333
RfcWithAuthorsSerializer,
3434
DraftWithAuthorsSerializer,
35-
NotificationAckSerializer, RfcPubSerializer, RfcFileSerializer,
35+
NotificationAckSerializer,
36+
RfcPubSerializer,
37+
RfcFileSerializer,
3638
EditableRfcSerializer,
3739
)
3840
from ietf.doc.models import Document, DocHistory, RfcAuthor, DocEvent
@@ -344,9 +346,10 @@ def post(self, request):
344346

345347
class RfcAuthorViewSet(viewsets.ReadOnlyModelViewSet):
346348
"""ViewSet for RfcAuthor model
347-
349+
348350
Router needs to provide rfc_number as a kwarg
349351
"""
352+
350353
api_key_endpoint = "ietf.api.views_rpc"
351354

352355
queryset = RfcAuthor.objects.all()
@@ -407,7 +410,7 @@ class RfcPubFilesView(APIView):
407410

408411
def _fs_destination(self, filename: str | Path) -> Path:
409412
"""Destination for an uploaded RFC file in the filesystem
410-
413+
411414
Strips any path components in filename and returns an absolute Path.
412415
"""
413416
rfc_path = Path(settings.RFC_PATH)
@@ -419,7 +422,7 @@ def _fs_destination(self, filename: str | Path) -> Path:
419422

420423
def _blob_destination(self, filename: str | Path) -> str:
421424
"""Destination name for an uploaded RFC file in the blob store
422-
425+
423426
Strips any path components in filename and returns an absolute Path.
424427
"""
425428
filename = Path(filename) # could potentially have directory components
@@ -472,9 +475,7 @@ def post(self, request):
472475
code="files-exist",
473476
)
474477
for possible_existing_blob in possible_rfc_blobs:
475-
if exists_in_storage(
476-
kind=blob_kind, name=possible_existing_blob
477-
):
478+
if exists_in_storage(kind=blob_kind, name=possible_existing_blob):
478479
raise Conflict(
479480
"Blob(s) already exist for this RFC",
480481
code="blobs-exist",
@@ -523,7 +524,9 @@ def post(self, request):
523524

524525
# Trigger red precomputer
525526
needs_updating = [rfc.rfc_number]
526-
for rel in rfc.relateddocument_set.filter(relationship_id__in=["obs","updates"]):
527+
for rel in rfc.relateddocument_set.filter(
528+
relationship_id__in=["obs", "updates"]
529+
):
527530
needs_updating.append(rel.target.rfc_number)
528531
trigger_red_precomputer_task.delay(rfc_number_list=sorted(needs_updating))
529532
# Trigger search index update
@@ -540,7 +543,7 @@ class RfcIndexView(APIView):
540543
@extend_schema(
541544
operation_id="refresh_rfc_index",
542545
summary="Refresh rfc-index files",
543-
description="Requests creation of rfc-index.xml and rfc-index.txt files",
546+
description="Requests creation of various index files.",
544547
responses={202: None},
545548
request=None,
546549
)

ietf/sync/tasks.py

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
from ietf.sync import iana
1919
from ietf.sync import rfceditor
2020
from ietf.sync.rfceditor import MIN_QUEUE_RESULTS, parse_queue, update_drafts_from_queue
21-
from ietf.sync.rfcindex import create_rfc_txt_index, create_rfc_xml_index
21+
from ietf.sync.rfcindex import (
22+
create_bcp_txt_index,
23+
create_fyi_txt_index,
24+
create_rfc_txt_index,
25+
create_rfc_xml_index,
26+
create_std_txt_index,
27+
)
2228
from ietf.sync.utils import build_from_file_content, load_rfcs_into_blobdb, rsync_helper
2329
from ietf.utils import log
2430
from ietf.utils.timezone import date_today
@@ -27,13 +33,13 @@
2733
@shared_task
2834
def rfc_editor_index_update_task(full_index=False):
2935
"""Update metadata from the RFC index
30-
36+
3137
Default is to examine only changes in the past 365 days. Call with full_index=True to update
3238
the full RFC index.
33-
39+
3440
According to comments on the original script, a year's worth took about 20s on production as of
3541
August 2022
36-
42+
3743
The original rfc-editor-index-update script had a long-disabled provision for running the
3844
rebuild_reference_relations scripts after the update. That has not been brought over
3945
at all because it should be implemented as its own task if it is needed.
@@ -51,7 +57,7 @@ def rfc_editor_index_update_task(full_index=False):
5157
timeout=30, # seconds
5258
)
5359
except requests.Timeout as exc:
54-
log.log(f'GET request timed out retrieving RFC editor index: {exc}')
60+
log.log(f"GET request timed out retrieving RFC editor index: {exc}")
5561
return # failed
5662
rfc_index_xml = response.text
5763
index_data = rfceditor.parse_index(io.StringIO(rfc_index_xml))
@@ -61,9 +67,9 @@ def rfc_editor_index_update_task(full_index=False):
6167
timeout=30, # seconds
6268
)
6369
except requests.Timeout as exc:
64-
log.log(f'GET request timed out retrieving RFC editor errata: {exc}')
70+
log.log(f"GET request timed out retrieving RFC editor errata: {exc}")
6571
return # failed
66-
errata_data = response.json()
72+
errata_data = response.json()
6773
if len(index_data) < rfceditor.MIN_INDEX_RESULTS:
6874
log.log("Not enough index entries, only %s" % len(index_data))
6975
return # failed
@@ -96,15 +102,15 @@ def rfc_editor_queue_updates_task():
96102
drafts, warnings = parse_queue(io.StringIO(response.text))
97103
for w in warnings:
98104
log.log(f"Warning: {w}")
99-
105+
100106
if len(drafts) < MIN_QUEUE_RESULTS:
101107
log.log("Not enough results, only %s" % len(drafts))
102108
return # failed
103-
109+
104110
changed, warnings = update_drafts_from_queue(drafts)
105111
for w in warnings:
106112
log.log(f"Warning: {w}")
107-
113+
108114
for c in changed:
109115
log.log(f"Updated {c}")
110116

@@ -120,9 +126,11 @@ def iana_changes_update_task():
120126
MAX_INTERVAL_ACCEPTED_BY_IANA = datetime.timedelta(hours=23)
121127

122128
start = (
123-
timezone.now()
124-
- datetime.timedelta(hours=23)
125-
+ datetime.timedelta(seconds=CLOCK_SKEW_COMPENSATION,)
129+
timezone.now()
130+
- datetime.timedelta(hours=23)
131+
+ datetime.timedelta(
132+
seconds=CLOCK_SKEW_COMPENSATION,
133+
)
126134
)
127135
end = start + datetime.timedelta(hours=23)
128136

@@ -133,7 +141,9 @@ def iana_changes_update_task():
133141
# requests if necessary
134142

135143
text = iana.fetch_changes_json(
136-
settings.IANA_SYNC_CHANGES_URL, t, min(end, t + MAX_INTERVAL_ACCEPTED_BY_IANA)
144+
settings.IANA_SYNC_CHANGES_URL,
145+
t,
146+
min(end, t + MAX_INTERVAL_ACCEPTED_BY_IANA),
137147
)
138148
log.log(f"Retrieved the JSON: {text}")
139149

@@ -159,9 +169,9 @@ def iana_protocols_update_task():
159169
# "this needs to be the date where this tool is first deployed" in the original
160170
# iana-protocols-updates script)"
161171
rfc_must_published_later_than = datetime.datetime(
162-
2012,
163-
11,
164-
26,
172+
2012,
173+
11,
174+
26,
165175
tzinfo=datetime.UTC,
166176
)
167177

@@ -171,17 +181,17 @@ def iana_protocols_update_task():
171181
timeout=30,
172182
)
173183
except requests.Timeout as exc:
174-
log.log(f'GET request timed out retrieving IANA protocols page: {exc}')
184+
log.log(f"GET request timed out retrieving IANA protocols page: {exc}")
175185
return
176186

177187
rfc_numbers = iana.parse_protocol_page(response.text)
178188

179189
def batched(l, n):
180190
"""Split list l up in batches of max size n.
181-
191+
182192
For Python 3.12 or later, replace this with itertools.batched()
183193
"""
184-
return (l[i:i + n] for i in range(0, len(l), n))
194+
return (l[i : i + n] for i in range(0, len(l), n))
185195

186196
for batch in batched(rfc_numbers, 100):
187197
updated = iana.update_rfc_log_from_protocol_page(
@@ -192,6 +202,7 @@ def batched(l, n):
192202
for d in updated:
193203
log.log("Added history entry for %s" % d.display_name())
194204

205+
195206
@shared_task
196207
def fix_subseries_docevents_task():
197208
"""Repairs DocEvents related to bugs around removing docs from subseries
@@ -233,6 +244,7 @@ def fix_subseries_docevents_task():
233244
time=obsoleting_time
234245
)
235246

247+
236248
@shared_task
237249
def rsync_rfcs_from_rfceditor_task(rfc_numbers: list[int]):
238250
log.log(f"Rsyncing rfcs from rfc-editor: {rfc_numbers}")
@@ -277,6 +289,32 @@ def load_rfcs_into_blobdb_task(start: int, end: int):
277289

278290
@shared_task
279291
def create_rfc_index_task():
280-
create_rfc_txt_index()
281-
create_rfc_xml_index()
292+
try:
293+
create_rfc_txt_index()
294+
except Exception as e:
295+
log.log(f"Error: failure in creating rfc-index.txt. {e}")
296+
pass
282297

298+
try:
299+
create_rfc_xml_index()
300+
except Exception as e:
301+
log.log(f"Error: failure in creating rfc-index.xml. {e}")
302+
pass
303+
304+
try:
305+
create_bcp_txt_index()
306+
except Exception as e:
307+
log.log(f"Error: failure in creating bcp-index.txt. {e}")
308+
pass
309+
310+
try:
311+
create_std_txt_index()
312+
except Exception as e:
313+
log.log(f"Error: failure in creating std-index.txt. {e}")
314+
pass
315+
316+
try:
317+
create_fyi_txt_index()
318+
except Exception as e:
319+
log.log(f"Error: failure in creating fyi-index.txt. {e}")
320+
pass

0 commit comments

Comments
 (0)