From 5899ed64ec2c0347baba53281222a35fe6b06d0b Mon Sep 17 00:00:00 2001 From: Soufyan Abdellati Date: Thu, 31 Oct 2024 09:32:32 +0100 Subject: [PATCH] Removed unneeded attributes of normalizers' tasks --- boefjes/boefjes/app.py | 3 +-- boefjes/boefjes/clients/scheduler_client.py | 16 ++++++++++++---- mula/scheduler/models/task.py | 2 -- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/boefjes/boefjes/app.py b/boefjes/boefjes/app.py index e4cd9cf7095..b577af4d373 100644 --- a/boefjes/boefjes/app.py +++ b/boefjes/boefjes/app.py @@ -272,7 +272,7 @@ def get_runtime_manager(settings: Settings, queue: WorkerManager.Queue, log_leve plugin_service = PluginService(create_plugin_storage(session), create_config_storage(session), local_repository) item_handler: Handler - capabilities: list[str] + capabilities: list[str] | None = None reachable_networks: list[str] | None = None if queue is WorkerManager.Queue.BOEFJES: @@ -283,7 +283,6 @@ def get_runtime_manager(settings: Settings, queue: WorkerManager.Queue, log_leve item_handler = NormalizerHandler( LocalNormalizerJobRunner(local_repository), bytes_api_client, settings.scan_profile_whitelist ) - capabilities = [WorkerManager.Queue.NORMALIZERS.value] return SchedulerWorkerManager( item_handler, diff --git a/boefjes/boefjes/clients/scheduler_client.py b/boefjes/boefjes/clients/scheduler_client.py index 4db8e0572f8..f34a4645b33 100644 --- a/boefjes/boefjes/clients/scheduler_client.py +++ b/boefjes/boefjes/clients/scheduler_client.py @@ -69,7 +69,9 @@ def push_item(self, p_item: Task) -> None: class SchedulerAPIClient(SchedulerClientInterface): - def __init__(self, base_url: str, task_capabilities: list[str] = [], reachable_networks: list[str] | None = None): + def __init__( + self, base_url: str, task_capabilities: list[str] | None = None, reachable_networks: list[str] | None = None + ): self._session = Client(base_url=base_url, transport=HTTPTransport(retries=6)) self._task_capabilities = task_capabilities self._reachable_networks = reachable_networks @@ -85,15 +87,21 @@ def get_queues(self) -> list[Queue]: return TypeAdapter(list[Queue]).validate_json(response.content) def pop_item(self, queue_id: str) -> Task | None: - filters: list[Filter] = [ - Filter(column="data", field="requirements", operator="<@", value=json.dumps(self._task_capabilities)) - ] + filters: list[Filter] = [] + # Client should only pop tasks that lie on a network that the runner is capable of reaching (e.g. the internet) if self._reachable_networks: filters.append( Filter(column="data", field="network", operator="<@", value=json.dumps(self._reachable_networks)) ) + # Client should only pop tasks that have requirements that this runner is capable of (e.g. being able + # to handle ipv6 requests) + if self._task_capabilities: + filters.append( + Filter(column="data", field="requirements", operator="<@", value=json.dumps(self._task_capabilities)) + ) + response = self._session.post( f"/queues/{queue_id}/pop", data=QueuePopRequest(filters=filters).model_dump_json() ) diff --git a/mula/scheduler/models/task.py b/mula/scheduler/models/task.py index 7ee90728bc2..df190a3b4e6 100644 --- a/mula/scheduler/models/task.py +++ b/mula/scheduler/models/task.py @@ -99,8 +99,6 @@ class NormalizerTask(BaseModel): normalizer: Normalizer raw_data: RawData - requirements: list[str] | None = None - @property def hash(self) -> str: """Make NormalizerTask hashable, so that we can de-duplicate it when