Skip to content

Adding background jobs - #2502

Open
s3inlc wants to merge 11 commits into
886-stack-2-cracker-access-groupfrom
886-stack-3-background-jobs
Open

s3inlc wants to merge 11 commits into
886-stack-2-cracker-access-groupfrom
886-stack-3-background-jobs

Conversation

@s3inlc

@s3inlc s3inlc commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Introduces a generic, database-backed background job system for long-running server operations. Jobs store their type, JSON payload, triggering user, lifecycle timestamps, status, exit code, and result message. A locked runner processes pending jobs sequentially, prevents overlapping executions, records failures, and recovers stale jobs. The container entrypoint invokes the runner every 60 seconds, with an environment variable to disable the scheduler.

File line recounting is migrated to the new asynchronous flow, so UI and API requests enqueue work instead of blocking. A read/delete-only API exposes job status and results; running jobs cannot be deleted.

@s3inlc
s3inlc added this pull request to stack #2501 September 17, 2026 14:14
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch from 4fbe958 to dff4445 Compare September 18, 2026 12:59
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch from dff4445 to 5f4e06d Compare September 22, 2026 12:17
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch from 5f4e06d to 980a15e Compare September 22, 2026 12:43
@s3inlc
s3inlc marked this pull request as ready for review September 22, 2026 13:03
@s3inlc
s3inlc requested a review from jessevz September 22, 2026 13:03
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch from 706f061 to a29ccdf Compare September 23, 2026 07:29
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch 2 times, most recently from 0c293c7 to e521791 Compare September 23, 2026 09:13
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch 3 times, most recently from 0ac0a8f to 034c8ee Compare September 23, 2026 13:03
@s3inlc
s3inlc requested a lite review from Copilot September 23, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical and moderate review findings remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 1 Medium severity

Open (4)
What changed in this PR

Introduces a database-backed background-job system and moves file line recounting to asynchronous processing.

Changes:

  • Adds job persistence, handlers, runners, locking, recovery, and scheduling.
  • Exposes read/delete job APIs with OpenAPI support.
  • Updates recount flows, models, tests, and CI configuration.
File Description
src/​migrations/​postgres/​20260917160500_background-jobs.sql PostgreSQL job schema
src/​migrations/​mysql/​20260917160500_background-jobs.sql MySQL job schema
src/​inc/​utils/​UserUtils.php Detaches jobs from deleted users
src/​inc/​utils/​LockUtils.php Nonblocking lock acquisition
src/​inc/​utils/​Lock.php Background-job lock support
src/​inc/​utils/​FileUtils.php Validated file line counts
src/​inc/​utils/​BackgroundJobUtils.php Job enqueue and deletion helpers
src/​inc/​jobs/​handlers/​RecountFileJob.php File recount handler
src/​inc/​jobs/​BackgroundJobRunner.php Claims, executes, and recovers jobs
src/​inc/​jobs/​BackgroundJobResult.php Job result representation
src/​inc/​jobs/​BackgroundJobRegistry.php Handler registry
src/​inc/​jobs/​BackgroundJobHandler.php Handler contract
src/​inc/​handlers/​FileHandler.php Enqueues UI recount requests
src/​inc/​defines/​DBackgroundJobType.php Job type definitions
src/​inc/​defines/​DBackgroundJobStatus.php Job status definitions
src/​inc/​cron.php Runner entrypoint
src/​inc/​apiv2/​openapi/​SpecSanitizer.php OpenAPI value handling
src/​inc/​apiv2/​openapi/​RouteIntrospector.php Reflection imports
src/​inc/​apiv2/​openapi/​FeatureTypeMapper.php JSON field mapping
src/​inc/​apiv2/​model/​BackgroundJobAPI.php Background-job API
src/​inc/​apiv2/​helper/​RecountFileLinesHelperAPI.php Asynchronous recount flow
src/​inc/​apiv2/​common/​ApiRegistry.php API registration
src/​inc/​apiv2/​common/​AbstractBaseAPI.php JSON conversion and permissions
src/​dba/​models/​generator.php Job model metadata
src/​dba/​models/​BackgroundJobFactory.php Job factory
src/​dba/​models/​BackgroundJob.php Job model
src/​dba/​Factory.php Factory registration
src/​dba/​AbstractModelFactory.php JSON SQL handling and update results
openapi.json Generated API specification
docker-entrypoint.sh Scheduler loop
ci/​phpunit/​inc/​utils/​BackgroundJobUtilsTest.php Runner unit tests
ci/​phpunit/​dba/​UpdateSetTest.php Update result assertions
ci/​phpunit/​dba/​AbstractModelFactoryTest.php Mass-update assertions
ci/​apiv2/​utils.py Background-job test model
ci/​apiv2/​test_permissions.py Permission-flow coverage
ci/​apiv2/​test_file.py Recount API test updates
ci/​apiv2/​test_backgroundjob.py Background-job API tests
.github/​docker-compose.postgres.yml Disables scheduler in PostgreSQL CI
.github/​docker-compose.mysql.yml Disables scheduler in MySQL CI

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/inc/apiv2/model/BackgroundJobAPI.php Outdated
Comment thread src/inc/jobs/BackgroundJobRunner.php
Comment thread src/inc/utils/Lock.php
Comment thread docker-entrypoint.sh

@jessevz jessevz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good,

$factory = Factory::getBackgroundJobFactory();
while (true) {
$job = $factory->filter([
Factory::FILTER => new QueryFilter(BackgroundJob::STATUS, DBackgroundJobStatus::PENDING, "="),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great, but it would it be nice to also have support for reoccuring jobs. ex. cleaning the speed database every 10 minutes. It would be nice that instead of checking on pending, we can have a field with a time that the job is scheduled for, this can then work for both non occuring as occuring jobs, occuring jobs can then update this time after completing their job

Comment thread src/inc/jobs/BackgroundJobHandler.php
@s3inlc
s3inlc force-pushed the 886-stack-3-background-jobs branch from 3e75a63 to 0ee56d5 Compare October 1, 2026 12:59
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.

3 participants