Files
OpenNest/OpenNest.Server.Worker/Program.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

29 lines
1.6 KiB
C#

using System.Diagnostics;
using OpenNest.Data;
using OpenNest.Server.Worker;
// The nest server's worker: takes queued whole-job nests from OPENNEST_SERVER_URL and solves
// them one at a time, and measures library drawings for the library's size filters. Run it in
// its own container with CPU and memory limits (compose.server.yaml) so nesting never slows
// nest open and save. See docs/server-nesting.md.
var options = WorkerOptions.FromEnvironment(Environment.GetEnvironmentVariable);
// Below the server and anything else on the host when they share CPUs; the container's
// CPU limit is the real bound.
try { Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; }
catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or PlatformNotSupportedException) { }
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton(options);
builder.Services.AddSingleton(_ => new RemoteNestJobs(options.ServerUrl));
builder.Services.AddSingleton(sp => new NestJobWorker(
sp.GetRequiredService<RemoteNestJobs>(), sp.GetRequiredService<ILogger<NestJobWorker>>()));
builder.Services.AddHostedService<NestJobWorkerService>();
// Measures library drawings for the size and hole filters; see DrawingGeometryBackfill.
builder.Services.AddSingleton(_ => new RemoteDrawingGeometry(options.ServerUrl));
builder.Services.AddSingleton<DrawingGeometryBackfill>();
builder.Services.AddHostedService<DrawingGeometryBackfillService>();
// A running job is given back, not abandoned, when the container stops.
builder.Services.Configure<HostOptions>(o => o.ShutdownTimeout = TimeSpan.FromSeconds(20));
builder.Build().Run();