From 24442869c053cc66c277d08cebe0a8b05c799352 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Fri, 2 May 2025 17:45:30 +0300 Subject: [PATCH] fix queue update --- Azaion.CommonSecurity/DTO/DirectoriesConfig.cs | 1 + Azaion.CommonSecurity/DTO/ExternalClientsConfig.cs | 5 ++++- Azaion.CommonSecurity/SecurityConstants.cs | 2 -- Azaion.CommonSecurity/Services/AuthProvider.cs | 6 +++++- Azaion.CommonSecurity/Services/InferenceClient.cs | 3 +-- Azaion.Inference/config.production.yaml | 2 -- Azaion.Inference/config.yaml | 2 -- Azaion.Inference/main.pyx | 8 +------- Azaion.Inference/start.py | 12 +++++++++--- Azaion.Suite/App.xaml.cs | 2 +- Azaion.Suite/config.json | 3 ++- 11 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 Azaion.Inference/config.production.yaml delete mode 100644 Azaion.Inference/config.yaml diff --git a/Azaion.CommonSecurity/DTO/DirectoriesConfig.cs b/Azaion.CommonSecurity/DTO/DirectoriesConfig.cs index 5e84edd..2624485 100644 --- a/Azaion.CommonSecurity/DTO/DirectoriesConfig.cs +++ b/Azaion.CommonSecurity/DTO/DirectoriesConfig.cs @@ -1,6 +1,7 @@ namespace Azaion.CommonSecurity.DTO; public class DirectoriesConfig + { public string ApiResourcesDirectory { get; set; } = null!; diff --git a/Azaion.CommonSecurity/DTO/ExternalClientsConfig.cs b/Azaion.CommonSecurity/DTO/ExternalClientsConfig.cs index 691a922..33d66fb 100644 --- a/Azaion.CommonSecurity/DTO/ExternalClientsConfig.cs +++ b/Azaion.CommonSecurity/DTO/ExternalClientsConfig.cs @@ -8,7 +8,10 @@ public abstract class ExternalClientConfig public int RetryCount {get;set;} } -public class InferenceClientConfig : ExternalClientConfig; +public class InferenceClientConfig : ExternalClientConfig +{ + public string ApiUrl { get; set; } +} public class GpsDeniedClientConfig : ExternalClientConfig { diff --git a/Azaion.CommonSecurity/SecurityConstants.cs b/Azaion.CommonSecurity/SecurityConstants.cs index 2498753..8da1753 100644 --- a/Azaion.CommonSecurity/SecurityConstants.cs +++ b/Azaion.CommonSecurity/SecurityConstants.cs @@ -9,8 +9,6 @@ public class SecurityConstants public const string DUMMY_DIR = "dummy"; #region ExternalClientsConfig - //public const string API_URL = "http://localhost:5219"; - public const string API_URL = "https://api.azaion.com"; public const string EXTERNAL_INFERENCE_PATH = "azaion-inference.exe"; public const string EXTERNAL_GPS_DENIED_FOLDER = "gps-denied"; diff --git a/Azaion.CommonSecurity/Services/AuthProvider.cs b/Azaion.CommonSecurity/Services/AuthProvider.cs index 4baabf5..be47e62 100644 --- a/Azaion.CommonSecurity/Services/AuthProvider.cs +++ b/Azaion.CommonSecurity/Services/AuthProvider.cs @@ -34,7 +34,11 @@ public class AzaionApi(HttpClient client, ICache cache, ApiCredentials credentia public void UpdateOffsets(UserQueueOffsets offsets) { - Put($"/users/queue-offsets/{CurrentUser.Email}", offsets); + Put($"/users/queue-offsets/set", new + { + Email = CurrentUser.Email, + Offsets = offsets + }); } private HttpResponseMessage Send(HttpRequestMessage request) diff --git a/Azaion.CommonSecurity/Services/InferenceClient.cs b/Azaion.CommonSecurity/Services/InferenceClient.cs index cad5c98..c7b5dc9 100644 --- a/Azaion.CommonSecurity/Services/InferenceClient.cs +++ b/Azaion.CommonSecurity/Services/InferenceClient.cs @@ -38,7 +38,7 @@ public class InferenceClient : IInferenceClient process.StartInfo = new ProcessStartInfo { FileName = SecurityConstants.EXTERNAL_INFERENCE_PATH, - //Arguments = $"-e {credentials.Email} -p {credentials.Password} -f {apiConfig.ResourcesFolder}", + Arguments = $"--port {_inferenceClientConfig.ZeroMqPort} --api {_inferenceClientConfig.ApiUrl}", //RedirectStandardOutput = true, //RedirectStandardError = true, //CreateNoWindow = true @@ -57,7 +57,6 @@ public class InferenceClient : IInferenceClient _dealer.Options.Identity = Encoding.UTF8.GetBytes(_clientId.ToString("N")); _dealer.Connect($"tcp://{_inferenceClientConfig.ZeroMqHost}:{_inferenceClientConfig.ZeroMqPort}"); } - private async Task ProcessClientCommands() { //TODO: implement always on ready to client's requests. Utilize RemoteCommand diff --git a/Azaion.Inference/config.production.yaml b/Azaion.Inference/config.production.yaml deleted file mode 100644 index 839b6fc..0000000 --- a/Azaion.Inference/config.production.yaml +++ /dev/null @@ -1,2 +0,0 @@ -zmq_port: 5131 -api_url: https://api.azaion.com \ No newline at end of file diff --git a/Azaion.Inference/config.yaml b/Azaion.Inference/config.yaml deleted file mode 100644 index 3317558..0000000 --- a/Azaion.Inference/config.yaml +++ /dev/null @@ -1,2 +0,0 @@ -zmq_port: 5127 -api_url: http://localhost:5219 \ No newline at end of file diff --git a/Azaion.Inference/main.pyx b/Azaion.Inference/main.pyx index a29e512..fbb806f 100644 --- a/Azaion.Inference/main.pyx +++ b/Azaion.Inference/main.pyx @@ -13,7 +13,6 @@ from remote_command cimport RemoteCommand, CommandType from remote_command_handler cimport RemoteCommandHandler from credentials cimport Credentials from file_data cimport FileData -from user cimport User cdef class CommandProcessor: cdef ApiClient api_client @@ -22,12 +21,7 @@ cdef class CommandProcessor: cdef bint running cdef Inference inference - def __init__(self): - with open(constants.CONFIG_FILE, "r") as f: - config = yaml.safe_load(f) - zmq_port = config["zmq_port"] - api_url = config["api_url"] - + def __init__(self, int zmq_port, str api_url): self.api_client = ApiClient(api_url) self.remote_handler = RemoteCommandHandler(zmq_port, self.on_command) self.inference_queue = Queue(maxsize=constants.QUEUE_MAXSIZE) diff --git a/Azaion.Inference/start.py b/Azaion.Inference/start.py index 00675fb..5f3ede1 100644 --- a/Azaion.Inference/start.py +++ b/Azaion.Inference/start.py @@ -1,8 +1,9 @@ from main import CommandProcessor +import argparse -def start(): - processor = CommandProcessor() +def start(zmq_port, api_url): + processor = CommandProcessor(zmq_port, api_url) try: processor.start() except KeyboardInterrupt: @@ -10,4 +11,9 @@ def start(): if __name__ == '__main__': - start() + parser = argparse.ArgumentParser() + parser.add_argument("-p", "--port", type=str, default="5127", help="zero mq port") + parser.add_argument("-a", "--api", type=str, default="https://api.azaion.com", help="api url") + args = parser.parse_args() + + start(int(args.port), args.api) diff --git a/Azaion.Suite/App.xaml.cs b/Azaion.Suite/App.xaml.cs index e2471e0..bd8a258 100644 --- a/Azaion.Suite/App.xaml.cs +++ b/Azaion.Suite/App.xaml.cs @@ -96,7 +96,7 @@ public partial class App login.CredentialsEntered += (_, credentials) => { _inferenceClient.Send(RemoteCommand.Create(CommandType.Login, credentials)); - _azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(SecurityConstants.API_URL) }, _cache, credentials); + _azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(secureAppConfig.InferenceClientConfig.ApiUrl) }, _cache, credentials); try { diff --git a/Azaion.Suite/config.json b/Azaion.Suite/config.json index 64eeb8c..f5c76fd 100644 --- a/Azaion.Suite/config.json +++ b/Azaion.Suite/config.json @@ -3,7 +3,8 @@ "ZeroMqHost": "127.0.0.1", "ZeroMqPort": 5127, "RetryCount": 25, - "TimeoutSeconds": 5 + "TimeoutSeconds": 5, + "ApiUrl": "https://api.azaion.com" }, "GpsDeniedClientConfig": { "ZeroMqHost": "127.0.0.1",