Issue #21: implement worker bootstrap and options

This commit is contained in:
Joseph Doherty
2026-04-26 16:53:06 -04:00
parent e2b4dfcb32
commit 0af1427859
19 changed files with 736 additions and 2 deletions
+62 -1
View File
@@ -1,16 +1,77 @@
using System;
using System.Collections.Generic;
using MxGateway.Worker.Bootstrap;
namespace MxGateway.Worker;
public static class WorkerApplication
{
public static int Run(string[] args)
{
return Run(
args,
new EnvironmentVariableWorkerEnvironment(),
new WorkerConsoleLogger(Console.Error));
}
public static int Run(
string[] args,
IWorkerEnvironment environment,
IWorkerLogger logger)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
return 0;
if (environment is null)
{
throw new ArgumentNullException(nameof(environment));
}
if (logger is null)
{
throw new ArgumentNullException(nameof(logger));
}
try
{
WorkerOptionsParser parser = new(environment);
WorkerBootstrapResult result = parser.Parse(args);
if (!result.Succeeded)
{
logger.Error("WorkerBootstrapFailed", new Dictionary<string, object?>
{
["exit_code"] = result.ExitCode,
["errors"] = string.Join(";", result.Errors),
});
return (int)result.ExitCode;
}
WorkerOptions options = result.Options
?? throw new InvalidOperationException("Successful bootstrap result did not include worker options.");
logger.Information("WorkerBootstrapSucceeded", new Dictionary<string, object?>
{
["session_id"] = options.SessionId,
["pipe_name"] = options.PipeName,
["protocol_version"] = options.ProtocolVersion,
["nonce"] = options.Nonce,
});
return (int)WorkerExitCode.Success;
}
catch (Exception exception)
{
logger.Error("WorkerBootstrapUnexpectedFailure", new Dictionary<string, object?>
{
["exit_code"] = WorkerExitCode.UnexpectedFailure,
["exception_type"] = exception.GetType().FullName,
});
return (int)WorkerExitCode.UnexpectedFailure;
}
}
}