Use local_paths when submitting jobs to localhost

This commit is contained in:
Brett Williams
2023-06-15 20:45:46 -05:00
parent 79ff451af8
commit 0080cdb371
3 changed files with 20 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ import logging
import os
import json
import requests
import socket
import time
import threading
from lib.workers.base_worker import RenderStatus
@@ -115,10 +116,17 @@ class RenderServerProxy:
timeout=1) or {}
return request_data.get('is_available', False)
def post_job_to_server(self, input_path, job_list, callback=None):
def post_job_to_server(self, file_path, job_list, callback=None):
# bypass uploading file if posting to localhost
if self.hostname == socket.gethostname():
jobs_with_path = [{**item, "local_path": file_path} for item in job_list]
return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=json.dumps(jobs_with_path),
headers={'Content-Type': 'application/json'})
# Prepare the form data
encoder = MultipartEncoder({
'file': (os.path.basename(input_path), open(input_path, 'rb'), 'application/octet-stream'),
'file': (os.path.basename(file_path), open(file_path, 'rb'), 'application/octet-stream'),
'json': (None, json.dumps(job_list), 'application/json'),
})
@@ -130,9 +138,7 @@ class RenderServerProxy:
# Send the request
headers = {'Content-Type': monitor.content_type}
response = requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=monitor, headers=headers)
return response
return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=monitor, headers=headers)
def get_job_files(self, job_id, save_path):
url = f"http://{self.hostname}:{self.port}/api/job/{job_id}/download_all"