Skip to content

Commit f7ef79d

Browse files
authored
Update az.py (kevoreilly#2906)
* Update az.py * Update az.py
1 parent f99ae04 commit f7ef79d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

modules/machinery/az.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# in https://github.com/CheckPointSW/Cuckoo-AWS.
33
# Modified by the Canadian Centre for Cyber Security to support Azure.
44

5-
import itertools
65
import logging
76
import re
87
import socket
@@ -1388,22 +1387,21 @@ def _get_number_of_relevant_tasks(self, tag, platform=None):
13881387
"""
13891388
# Fix: Count BOTH pending AND running tasks
13901389
# 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}")
13931391

13941392
# The task queue that will be used to prepare machines will be relative to the virtual
13951393
# machine tag that is targeted in the task (win7, win10, etc) or platform (windows, linux)
13961394
relevant_task_queue = 0
13971395

13981396
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+
)
14031400
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
14071405
return relevant_task_queue
14081406

14091407
def _get_relevant_machines(self, tag):

0 commit comments

Comments
 (0)