Skip to content

First release: job queue, storage adapters, scheduler, worker and runner - #1

Merged
callismart merged 1 commit into
mainfrom
first-release
Dec 6, 2026
Merged

callismart merged 1 commit into
mainfrom
first-release

Conversation

@callismart

Copy link
Copy Markdown
Member

Summary

First release of callismart/background: Smart License Server's background jobs engine, extracted so any app can reuse it.

  • Job queue with storage as a contract (JobStorageAdapterInterface). It ships four adapters:
    • database: MySQL, MariaDB, PostgreSQL and SQLite through DBPrism;
    • Redis, using Lua scripts;
    • file: one locked JSON file with atomic writes;
    • in-memory.
  • Scheduler: interval and calendar schedules, time zones per task or per scheduler. Its state goes through a store (file, memory, or callbacks into the app's own settings).
  • Queue worker: builds handlers through a PSR-11 container, a callback, or new $class(). It stops cleanly on SIGTERM and SIGINT, and works within a time budget for cron and web requests.
  • BackgroundRunner with PauseSignalInterface, a lock, a min_interval throttle, and BackgroundStatus heartbeats.
  • Translation hook, the same as in callismart/cache and callismart/mail.

Fixes compared with the code in smliser

These will reach smliser when it switches to the package:

  • A scalar job result read back as []; it is now stored as any JSON value.
  • remove_job() returned true even when nothing was deleted.
  • Lock files were deleted after use, which let two runs hold "the" lock at once. They are now kept.
  • Claims on SQLite, which has no row locks, are now guarded, so two workers can't take the same job.
  • Dates came out in non-UTC time zones when PHP's default time zone wasn't UTC. All dates are UTC now.
  • Listing a job whose class had been removed threw an exception. The worker now fails that job instead.
  • Descriptions weren't translated, or were built by concatenation. "Every 900 seconds" now reads "Every 15 minutes".

Tests

  • 290 tests: 123 unit tests, plus every storage adapter through one shared contract suite.
  • The contract suite includes a test with 6 processes claiming from the same queue.
  • Run locally against SQLite, MariaDB, PostgreSQL 16 and Redis 7.
  • CI runs PHP 8.1–8.4 with Redis, MySQL 8.4 and PostgreSQL 16 services, plus a code-style job. composer cs:check is clean.

After merging

  1. Tag v1.0.0 and submit the package to Packagist.
  2. Open a smliser PR that switches to the package. That PR will cover the adapters, the CodeChangeDetector pause signal, settings-backed scheduler state, the core tasks, translations, and the changelog.

Generated by Claude Code

Extracted from Smart License Server's background jobs engine into the
Callismart\Background namespace, with the queue storage as a contract
and four adapters: database (DBPrism), Redis, file and in-memory. All
pass one contract test suite, including concurrent workers.

The scheduler keeps its state through a store interface and supports
time zones; the worker builds handlers through a PSR-11 container, a
callback or new $class(); the runner takes a pause signal and keeps
heartbeats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWezTj9wtraoPhmyd5hNtG
@callismart
callismart merged commit cd33b37 into main Dec 6, 2026
5 checks passed
@callismart
callismart deleted the first-release branch December 6, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants