|
1 | 1 | import logging |
2 | 2 | import traceback |
3 | 3 | import urllib.parse |
| 4 | +from queue import Queue |
4 | 5 |
|
5 | 6 | import requests |
6 | 7 | import requests.adapters |
|
14 | 15 |
|
15 | 16 | class BuilderSupervisor(BaseSupervisor): |
16 | 17 |
|
17 | | - def __init__(self, config, builders, terminated_event, task_queue): |
| 18 | + def __init__( |
| 19 | + self, |
| 20 | + config, |
| 21 | + builders, |
| 22 | + terminated_event, |
| 23 | + task_queue: Queue, |
| 24 | + ): |
18 | 25 | self.__session = None |
19 | 26 | self.__task_queue = task_queue |
20 | 27 | self.__cached_config = TTLCache( |
@@ -44,42 +51,47 @@ def __generate_request_session(self): |
44 | 51 | self.__session.mount('https://', adapter) |
45 | 52 |
|
46 | 53 | def __request_build_task(self): |
47 | | - if not self.__task_queue.full(): |
48 | | - supported_arches = [self.config.base_arch] |
49 | | - excluded_packages = self.get_excluded_packages() |
50 | | - if self.config.base_arch == 'x86_64': |
51 | | - supported_arches.append('i686') |
52 | | - if self.config.build_src: |
53 | | - supported_arches.append('src') |
54 | | - full_url = urllib.parse.urljoin( |
55 | | - self.config.master_url, 'build_node/get_task' |
| 54 | + if self.__task_queue.unfinished_tasks >= self.config.threads_count: |
| 55 | + return {} |
| 56 | + supported_arches = [self.config.base_arch] |
| 57 | + excluded_packages = self.get_excluded_packages() |
| 58 | + if self.config.base_arch == 'x86_64': |
| 59 | + supported_arches.append('i686') |
| 60 | + if self.config.build_src: |
| 61 | + supported_arches.append('src') |
| 62 | + full_url = urllib.parse.urljoin( |
| 63 | + self.config.master_url, 'build_node/get_task' |
| 64 | + ) |
| 65 | + data = { |
| 66 | + 'supported_arches': supported_arches, |
| 67 | + 'excluded_packages': excluded_packages, |
| 68 | + } |
| 69 | + try: |
| 70 | + response = self.__session.post( |
| 71 | + full_url, |
| 72 | + json=data, |
| 73 | + timeout=self.config.request_timeout, |
56 | 74 | ) |
57 | | - data = { |
58 | | - 'supported_arches': supported_arches, |
59 | | - 'excluded_packages': excluded_packages, |
60 | | - } |
61 | | - try: |
62 | | - response = self.__session.post( |
63 | | - full_url, json=data, timeout=self.config.request_timeout |
64 | | - ) |
65 | | - response.raise_for_status() |
66 | | - return response.json() |
67 | | - except Exception: |
68 | | - logging.error( |
69 | | - "Can't report active task to master:\n%s", |
70 | | - traceback.format_exc(), |
71 | | - ) |
| 75 | + response.raise_for_status() |
| 76 | + return response.json() |
| 77 | + except Exception: |
| 78 | + logging.exception( |
| 79 | + "Failed to request build task from master:", |
| 80 | + ) |
| 81 | + return {} |
72 | 82 |
|
73 | 83 | def __report_active_tasks(self): |
74 | 84 | active_tasks = self.get_active_tasks() |
75 | | - logging.debug('Sending active tasks: {}'.format(active_tasks)) |
| 85 | + logging.debug('Sending active tasks: %s', active_tasks) |
76 | 86 | full_url = urllib.parse.urljoin( |
77 | 87 | self.config.master_url, 'build_node/ping' |
78 | 88 | ) |
79 | 89 | data = {'active_tasks': [int(item) for item in active_tasks]} |
80 | 90 | try: |
81 | 91 | self.__session.post( |
82 | | - full_url, json=data, timeout=self.config.request_timeout |
| 92 | + full_url, |
| 93 | + json=data, |
| 94 | + timeout=self.config.request_timeout, |
83 | 95 | ) |
84 | 96 | except Exception: |
85 | 97 | logging.error( |
@@ -110,7 +122,6 @@ def get_excluded_packages(self): |
110 | 122 | logging.debug('Excluded packages in this node: %s', excluded_packages) |
111 | 123 | return excluded_packages |
112 | 124 |
|
113 | | - |
114 | 125 | def run(self): |
115 | 126 | self.__generate_request_session() |
116 | 127 | while not self.terminated_event.is_set(): |
|
0 commit comments