Add machine_id parameter to remote_fetch method
Updated the remote_fetch method to accept a mandatory machine_id parameter and adjusted the URL endpoint accordingly. Modified relevant invocation and added error handling for missing machine_id. Updated the corresponding tests to include the machine_id parameter.
This commit is contained in:
parent
e6c7b76ccd
commit
1da8c3ae39
@ -59,7 +59,7 @@ class ArchiveSynchronizer(Component):
|
||||
self.gcs_bucket = None
|
||||
if "--dev-portal" in sys.argv:
|
||||
self.update_machine_status()
|
||||
self.remote_fetch(self.machine_status)
|
||||
self.remote_fetch(self.machine_status,self.machine_id)
|
||||
super()._get()
|
||||
|
||||
def update_machine_status(self):
|
||||
@ -157,15 +157,18 @@ class ArchiveSynchronizer(Component):
|
||||
self.log.info(f"id: {record.id}: stored remotely")
|
||||
return True
|
||||
|
||||
def remote_fetch(self, machine_status="logged-in"):
|
||||
def remote_fetch(self, machine_status="logged-in", machine_id=None):
|
||||
"""
|
||||
Fetch and download files from the server.
|
||||
|
||||
:param machine_status: Status of the machine (e.g., 'logged-in').
|
||||
:param machine_id: ID of the machine.
|
||||
:return: A list of downloaded file paths or a dictionary with errors if any occur.
|
||||
"""
|
||||
# URLs endpoint from your Django server
|
||||
urls_endpoint = "http://dev.r5portal.it/get-file-urls/"
|
||||
# URLs endpoint from your Django server with machine_id as a query parameter
|
||||
if machine_id is None:
|
||||
raise ValueError("machine_id cannot be None")
|
||||
urls_endpoint = f"http://dev.r5portal.it/get-file-urls/?machine_id={machine_id}"
|
||||
|
||||
if machine_status == "logged-in":
|
||||
try:
|
||||
@ -181,6 +184,7 @@ class ArchiveSynchronizer(Component):
|
||||
self.log.info(f"HTTP Status Code: {response.status_code}")
|
||||
self.log.info(f"Response Headers: {response.headers}")
|
||||
self.log.info(f"Response Content: {response.content}")
|
||||
|
||||
# Handle HTTP errors for the list of URLs fetch
|
||||
if response.status_code == 404:
|
||||
self.log.warning(f"URLs endpoint not found: {urls_endpoint}. Please check the URL path.")
|
||||
@ -201,6 +205,7 @@ class ArchiveSynchronizer(Component):
|
||||
self.log.error(f"Error parsing JSON response: {str(e)}")
|
||||
self.log.error(f"Response Content: {response.content}")
|
||||
return {"error": "Failed to parse JSON response"}
|
||||
|
||||
downloaded_files = []
|
||||
errors = {}
|
||||
|
||||
|
||||
@ -10,5 +10,6 @@ app = QApplication(sys.argv)
|
||||
|
||||
test= ArchiveSynchronizer(config=config, name="remote_fetch_test")
|
||||
status = "logged-in"
|
||||
result = test.remote_fetch(status)
|
||||
machine_id = "st-ten-6"
|
||||
result = test.remote_fetch(status,machine_id)
|
||||
print(result)
|
||||
Loading…
Reference in New Issue
Block a user