Files
OpenNest/OpenNest.Server.Worker/WorkerOptions.cs
T
ajandClaude Opus 5.5 b9fc618a50 feat(library): filter the drawing library by thickness, size, holes, date and customer
Finding a part on the nest server meant scrolling 40k drawings: the library
could only match an exact thickness or customer and knew nothing about a
drawing's size or holes. The library browser gets a Filter dialog with
inclusive ranges, and the query API takes them.

The server never parses packages and stays off IO, so the server worker now
measures each package beside its nest jobs (bounding sides, net area, closed
cutouts inside the outline) and stores the summary keyed by package hash
(schema v19). Identical geometry is measured once, an unreadable package is
recorded once instead of retried forever, and size or hole limits match only
measured drawings. Thickness ranges compare in inches across units and keep
the library's rule that a drawing saved without a thickness suits any.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:47:51 -05:00

42 lines
1.9 KiB
C#

namespace OpenNest.Server.Worker;
/// <summary>Worker settings read from the environment.</summary>
public sealed class WorkerOptions
{
public const string ServerVariable = "OPENNEST_SERVER_URL";
public const string PollVariable = "OPENNEST_WORKER_POLL_SECONDS";
public const string AliveVariable = "OPENNEST_WORKER_ALIVE_FILE";
/// <summary>The nest server the worker takes jobs from.</summary>
public required string ServerUrl { get; init; }
/// <summary>How long to wait before asking again when no job was queued.</summary>
public TimeSpan PollInterval { get; init; } = TimeSpan.FromSeconds(5);
/// <summary>How long library measurement waits before asking again when nothing was waiting.</summary>
public TimeSpan GeometryPollInterval { get; init; } = TimeSpan.FromSeconds(60);
/// <summary>Touched every round; the container health check fails when it goes stale.</summary>
public string AliveFile { get; init; } = Path.Combine(Path.GetTempPath(), "opennest-worker.alive");
public static WorkerOptions FromEnvironment(Func<string, string?> read)
{
var server = read(ServerVariable);
if (string.IsNullOrWhiteSpace(server))
throw new InvalidOperationException($"{ServerVariable} must name the nest server, for example http://opennest-server:8090/.");
var poll = TimeSpan.FromSeconds(5);
if (read(PollVariable) is { Length: > 0 } text)
{
if (!int.TryParse(text, out var seconds) || seconds is < 1 or > 3600)
throw new InvalidOperationException($"{PollVariable} must be whole seconds from 1 to 3600.");
poll = TimeSpan.FromSeconds(seconds);
}
return new WorkerOptions
{
ServerUrl = server.Trim(),
PollInterval = poll,
AliveFile = read(AliveVariable) is { Length: > 0 } alive ? alive : Path.Combine(Path.GetTempPath(), "opennest-worker.alive"),
};
}
}