Keep print jobs in the job store
The queue now keeps its jobs in a Store, the memory store for now, so that a store on disk can take its place. Submit stores the job as JSON before it answers, and the worker reads it back and decodes it when it takes it, so what prints is what was stored. Each job has one delivery, for the printer "default", and its status derives from its deliveries: queued while all wait, printing while any is unfinished, then failed over done once all have finished. Every change is committed to the store first and made in memory after, so a status never shows what the store lacks. Once the printer's connection is open and before the first byte, the worker records the attempt as sending; a failed dial records nothing. A failure is committed with a sync, since one rolled back to queued would print after a restart. A job's content goes in the commit that finishes it, as it went from memory before, and statuses past queue.history leave the store in the commit that finishes the job pushing them out. A job whose stored content no longer decodes fails without its content in the logs. A submit lock covers the capacity check, the insert and the append to the waiting list; the status lock is never held across a store call, so Status and Pending answer during a commit. A store error is returned, by Submit with nothing queued, or by Run, which ends; shutdown is as before. Part of stage 1c of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dbfabd1613
commit
14c5e86ab6
5 files changed
+914
-104
No files matched your search
@@ -87,7 +87,9 @@ func run(ctx context.Context, cfg *config.Config, build BuildInfo, out io.Writer
|
||||
printerClient := printer.NewClient(
|
||||
net.JoinHostPort(cfg.Printer.Address, strconv.Itoa(cfg.Printer.Port)),
|
||||
cfg.Printer.DialTimeout, cfg.Printer.WriteTimeout)
|
||||
queue := printqueue.New(renderer, printerClient, logger, printqueue.Options{
|
||||
store := printqueue.NewMemoryStore()
|
||||
defer closeStore(store, logger)
|
||||
queue := printqueue.New(renderer, printerClient, store, logger, printqueue.Options{
|
||||
Size: cfg.Queue.Size,
|
||||
History: cfg.Queue.History,
|
||||
Retries: cfg.Printer.Retries,
|
||||
@@ -212,6 +214,13 @@ func initSentry(cfg config.SentryConfig, build BuildInfo, logger *slog.Logger) (
|
||||
return func() { sentry.Flush(sentryFlushTimeout) }, nil
|
||||
}
|
||||
|
||||
// closeStore releases the job store once the daemon has stopped.
|
||||
func closeStore(store printqueue.Store, logger *slog.Logger) {
|
||||
if err := store.Close(); err != nil {
|
||||
logger.Error("closing the job store", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// reportJobFailure sends a failed print job to Sentry.
|
||||
func reportJobFailure(id printqueue.JobID, err error) {
|
||||
hub := sentry.CurrentHub().Clone()
|
||||
|
||||
Reference in new issue
Block a user