Skip to content

Commit 0ede2ed

Browse files
committed
Adds api as a SwarmingService property
1 parent d78a8eb commit 0ede2ed

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/clusterfuzz/_internal/swarming/service.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@
1919
from clusterfuzz._internal.remote_task import remote_task_types
2020
from clusterfuzz._internal.swarming.api import SwarmingAPI
2121

22-
_api = None
23-
24-
25-
def _get_api() -> SwarmingAPI:
26-
"""Returns a module-wide instance of SwarmingAPI."""
27-
global _api
28-
if _api is None:
29-
_api = SwarmingAPI()
30-
return _api
31-
3222

3323
class SwarmingService(remote_task_types.RemoteTaskInterface):
3424
"""Remote task service implementation for Swarming."""
3525

26+
_api: SwarmingAPI = None
27+
28+
def _get_api(self) -> SwarmingAPI:
29+
"""Returns the Swarming API instance."""
30+
if not self._api:
31+
self._api = SwarmingAPI()
32+
return self._api
33+
3634
def create_utask_main_job(self, module: str, job_type: str,
3735
input_download_url: str):
3836
"""Creates a single swarming task for a uworker main task."""
@@ -62,7 +60,7 @@ def create_utask_main_jobs(self,
6260
continue
6361
if request := swarming.create_new_task_request(
6462
task.command, task.job_type, task.argument):
65-
_get_api().push_task(request)
63+
self._get_api().push_task(request)
6664
except Exception: # pylint: disable=broad-except
6765
logs.error(
6866
f'Failed to push task to Swarming: {task.command}, {task.job_type}.'

0 commit comments

Comments
 (0)