Skip to content

Commit

Permalink
Using ABC
Browse files Browse the repository at this point in the history
  • Loading branch information
johannwagner committed Nov 19, 2024
1 parent e2d7c85 commit 800fe3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cosmo/clients/netbox_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def query(self, query):

def query_rest(self, path, queries):
q = urlencode(queries, doseq=True)
url = urljoin(self.url, path) + f"?{q}",
url = urljoin(self.url, path) + f"?{q}"

return_array = list()

Expand Down
9 changes: 6 additions & 3 deletions cosmo/clients/netbox_v4.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
from abc import ABC, abstractmethod
from builtins import map
from multiprocessing import Pool
from string import Template

from cosmo.clients.netbox_client import NetboxAPIClient


class ParallelQuery:
class ParallelQuery(ABC):

def __init__(self, client: NetboxAPIClient, **kwargs):
self.client = client
Expand All @@ -17,15 +18,17 @@ def __init__(self, client: NetboxAPIClient, **kwargs):
def fetch_data(self, pool):
return pool.apply_async(self._fetch_data, args=(self.kwargs,))

@abstractmethod
def _fetch_data(self, **kwargs):
raise NotImplementedError()
pass

def merge_into(self, data_promise, data: object):
query_data = data_promise.get()
return self._merge_into(data, query_data)

@abstractmethod
def _merge_into(self, data: object, query_result):
raise NotImplementedError()
pass


class ConnectedDevicesDataQuery(ParallelQuery):
Expand Down

0 comments on commit 800fe3c

Please sign in to comment.