15
15
Test_Import ,
16
16
)
17
17
from dojo .notifications .helper import create_notification
18
+ from dojo .decorators import we_want_async
18
19
from dojo .validators import clean_tags
19
20
20
21
logger = logging .getLogger (__name__ )
@@ -159,7 +160,7 @@ def process_findings(
159
160
from dojo .finding import helper as finding_helper
160
161
from dojo .models import Dojo_User
161
162
from dojo .utils import calculate_grade , calculate_grade_signature
162
- task_signatures = []
163
+ post_processing_task_signatures = []
163
164
164
165
"""
165
166
Saves findings in memory that were parsed from the scan report into the database.
@@ -233,29 +234,17 @@ def process_findings(
233
234
234
235
# Collect finding for parallel processing - we'll process them all at once after the loop
235
236
push_to_jira = self .push_to_jira and (not self .findings_groups_enabled or not self .group_by )
236
- # Process finding - either sync or async based on block_execution
237
- if Dojo_User .wants_block_execution (self .user ):
238
- # This will run synchronously, but we still call the dojo_async decorated function to count the task
239
- finding_helper .post_process_finding_save (
237
+ # Always create signatures - we'll execute them sync or async later
238
+ post_processing_task_signatures .append (
239
+ finding_helper .post_process_finding_save_signature (
240
240
finding ,
241
241
dedupe_option = True ,
242
242
rules_option = True ,
243
243
product_grading_option = False ,
244
244
issue_updater_option = True ,
245
245
push_to_jira = push_to_jira ,
246
- )
247
- else :
248
- # Add to task signatures for async execution
249
- task_signatures .append (
250
- finding_helper .post_process_finding_save_signature (
251
- finding ,
252
- dedupe_option = True ,
253
- rules_option = True ,
254
- product_grading_option = False ,
255
- issue_updater_option = True ,
256
- push_to_jira = push_to_jira ,
257
- ),
258
- )
246
+ ),
247
+ )
259
248
260
249
for (group_name , findings ) in group_names_to_findings_dict .items ():
261
250
finding_helper .add_findings_to_auto_group (
@@ -273,19 +262,18 @@ def process_findings(
273
262
274
263
# Calculate product grade after all findings are processed
275
264
product = self .test .engagement .product
276
- if task_signatures :
265
+ if post_processing_task_signatures :
277
266
# If we have async tasks, use chord to wait for them before calculating grade
278
- if Dojo_User .wants_block_execution (self .user ):
279
- # Run the chord synchronously by passing sync=True to each task
280
- for task_sig in task_signatures :
281
- task_sig .apply_async (sync = True ).get ()
282
- calculate_grade (product , sync = True )
267
+ if we_want_async (async_user = self .user ):
268
+ # Run the chord asynchronously and after completing post processing tasks, calculate grade ONCE
269
+ chord (post_processing_task_signatures )(calculate_grade_signature (product ))
283
270
else :
284
- # Run the chord asynchronously
285
- chord (task_signatures )(calculate_grade_signature (product ))
286
- else :
287
- # If everything was sync, calculate grade now as post processing is done
288
- calculate_grade (product )
271
+ # Execute each task synchronously
272
+ for task_sig in post_processing_task_signatures :
273
+ task_sig ()
274
+
275
+ # Calculate grade, which can be prelimary calculated before the async tasks have finished
276
+ calculate_grade (product )
289
277
290
278
sync = kwargs .get ("sync" , True )
291
279
if not sync :
0 commit comments