@@ -1226,16 +1226,21 @@ def _retry_validation(url_list, course_key, retry_count=3):
1226
1226
for i in range (0 , retry_count ):
1227
1227
if retry_list :
1228
1228
LOGGER .debug (f'[Link Check] retry attempt #{ i + 1 } ' )
1229
- validated_url_list = asyncio .run (
1230
- _validate_urls_access_in_batches (retry_list , course_key , batch_size = 100 )
1231
- )
1232
- filetered_url_list , retry_list = _filter_by_status (validated_url_list )
1233
- results .extend (filetered_url_list )
1234
-
1229
+ retry_list = _retry_validation_and_filter (course_key , results , retry_list )
1235
1230
results .extend (retry_list )
1236
1231
1237
1232
return results
1238
1233
1234
+
1235
+ def _retry_validation_and_filter (course_key , results , retry_list ):
1236
+ validated_url_list = asyncio .run (
1237
+ _validate_urls_access_in_batches (retry_list , course_key , batch_size = 100 )
1238
+ )
1239
+ filtered_url_list , retry_list = _filter_by_status (validated_url_list )
1240
+ results .extend (filtered_url_list )
1241
+ return retry_list
1242
+
1243
+
1239
1244
def _filter_by_status (results ):
1240
1245
"""
1241
1246
Filter results by status.
@@ -1262,6 +1267,15 @@ def _filter_by_status(results):
1262
1267
1263
1268
return filtered_results , retry_list
1264
1269
1270
+ def _save_broken_links_file (artifact , file_to_save ):
1271
+ artifact .file .save (name = os .path .basename (file_to_save .name ), content = File (file_to_save ))
1272
+ artifact .save ()
1273
+ return True
1274
+
1275
+ def _write_broken_links_to_file (broken_or_locked_urls , broken_links_file ):
1276
+ with open (broken_links_file .name , 'w' ) as file :
1277
+ json .dump (broken_or_locked_urls , file , indent = 4 )
1278
+
1265
1279
def _check_broken_links (task_instance , user_id , course_key_string , language ):
1266
1280
"""
1267
1281
Checks for broken links in a course. Store the results in a file.
@@ -1281,7 +1295,18 @@ def _check_broken_links(task_instance, user_id, course_key_string, language):
1281
1295
1282
1296
try :
1283
1297
task_instance .status .increment_completed_steps ()
1284
- _record_broken_links (task_instance , broken_or_locked_urls , course_key )
1298
+
1299
+ file_name = str (course_key )
1300
+ broken_links_file = NamedTemporaryFile (prefix = file_name + '.' , suffix = '.json' )
1301
+ LOGGER .debug (f'[Link Check] json file being generated at { broken_links_file .name } ' )
1302
+
1303
+ with open (broken_links_file .name , 'w' ) as file :
1304
+ json .dump (broken_or_locked_urls , file , indent = 4 )
1305
+
1306
+ _write_broken_links_to_file (broken_or_locked_urls , broken_links_file )
1307
+
1308
+ artifact = UserTaskArtifact (status = task_instance .status , name = 'BrokenLinks' )
1309
+ _save_broken_links_file (artifact , broken_links_file )
1285
1310
1286
1311
# catch all exceptions so we can record useful error messages
1287
1312
except Exception as e : # pylint: disable=broad-except
0 commit comments