Issue #22: implement pipe client and frame protocol
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MxGateway.Worker.Bootstrap;
|
||||
using MxGateway.Worker.Ipc;
|
||||
|
||||
namespace MxGateway.Worker;
|
||||
|
||||
@@ -11,13 +13,27 @@ public static class WorkerApplication
|
||||
return Run(
|
||||
args,
|
||||
new EnvironmentVariableWorkerEnvironment(),
|
||||
new WorkerConsoleLogger(Console.Error));
|
||||
new WorkerConsoleLogger(Console.Error),
|
||||
new WorkerPipeClient());
|
||||
}
|
||||
|
||||
public static int Run(
|
||||
string[] args,
|
||||
IWorkerEnvironment environment,
|
||||
IWorkerLogger logger)
|
||||
{
|
||||
return Run(
|
||||
args,
|
||||
environment,
|
||||
logger,
|
||||
new WorkerPipeClient());
|
||||
}
|
||||
|
||||
public static int Run(
|
||||
string[] args,
|
||||
IWorkerEnvironment environment,
|
||||
IWorkerLogger logger,
|
||||
IWorkerPipeClient pipeClient)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
@@ -34,6 +50,11 @@ public static class WorkerApplication
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (pipeClient is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pipeClient));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
WorkerOptionsParser parser = new(environment);
|
||||
@@ -61,8 +82,38 @@ public static class WorkerApplication
|
||||
["nonce"] = options.Nonce,
|
||||
});
|
||||
|
||||
pipeClient.RunAsync(options).GetAwaiter().GetResult();
|
||||
|
||||
logger.Information("WorkerPipeHandshakeSucceeded", new Dictionary<string, object?>
|
||||
{
|
||||
["session_id"] = options.SessionId,
|
||||
["pipe_name"] = options.PipeName,
|
||||
["protocol_version"] = options.ProtocolVersion,
|
||||
});
|
||||
|
||||
return (int)WorkerExitCode.Success;
|
||||
}
|
||||
catch (WorkerFrameProtocolException exception)
|
||||
{
|
||||
logger.Error("WorkerPipeProtocolFailure", new Dictionary<string, object?>
|
||||
{
|
||||
["exit_code"] = WorkerExitCode.ProtocolViolation,
|
||||
["error_code"] = exception.ErrorCode,
|
||||
["exception_type"] = exception.GetType().FullName,
|
||||
});
|
||||
|
||||
return (int)WorkerExitCode.ProtocolViolation;
|
||||
}
|
||||
catch (Exception exception) when (exception is IOException or TimeoutException)
|
||||
{
|
||||
logger.Error("WorkerPipeConnectionFailed", new Dictionary<string, object?>
|
||||
{
|
||||
["exit_code"] = WorkerExitCode.PipeConnectionFailed,
|
||||
["exception_type"] = exception.GetType().FullName,
|
||||
});
|
||||
|
||||
return (int)WorkerExitCode.PipeConnectionFailed;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.Error("WorkerBootstrapUnexpectedFailure", new Dictionary<string, object?>
|
||||
|
||||
Reference in New Issue
Block a user