|
2 | 2 | # in https://github.com/CheckPointSW/Cuckoo-AWS. |
3 | 3 | # Modified by the Canadian Centre for Cyber Security to support Azure. |
4 | 4 |
|
5 | | -import itertools |
6 | 5 | import logging |
7 | 6 | import re |
8 | 7 | import socket |
@@ -1388,22 +1387,21 @@ def _get_number_of_relevant_tasks(self, tag, platform=None): |
1388 | 1387 | """ |
1389 | 1388 | # Fix: Count BOTH pending AND running tasks |
1390 | 1389 | # Previous code only counted PENDING, causing VMs to be deleted while tasks running |
1391 | | - pending_tasks = self.db.list_tasks(status=TASK_PENDING) |
1392 | | - running_tasks = self.db.list_tasks(status=TASK_RUNNING) |
| 1390 | + current_tasks = self.db.list_tasks(status=f"{TASK_PENDING}|{TASK_RUNNING}") |
1393 | 1391 |
|
1394 | 1392 | # The task queue that will be used to prepare machines will be relative to the virtual |
1395 | 1393 | # machine tag that is targeted in the task (win7, win10, etc) or platform (windows, linux) |
1396 | 1394 | relevant_task_queue = 0 |
1397 | 1395 |
|
1398 | 1396 | if not platform: |
1399 | | - for task in itertools.chain(pending_tasks, running_tasks): |
1400 | | - for t in task.tags: |
1401 | | - if t.name == tag: |
1402 | | - relevant_task_queue += 1 |
| 1397 | + relevant_task_queue = sum( |
| 1398 | + 1 for task in current_tasks if any(t.name == tag for t in task.tags) |
| 1399 | + ) |
1403 | 1400 | else: |
1404 | | - for task in itertools.chain(pending_tasks, running_tasks): |
1405 | | - if task.platform == platform: |
1406 | | - relevant_task_queue += 1 |
| 1401 | + relevant_task_queue = sum( |
| 1402 | + 1 for task in current_tasks if task.platform == platform |
| 1403 | + ) |
| 1404 | + return relevant_task_queue |
1407 | 1405 | return relevant_task_queue |
1408 | 1406 |
|
1409 | 1407 | def _get_relevant_machines(self, tag): |
|
0 commit comments