Search by

bitshost / upmvc-jobs-pack

bitshost

Lightweight DB-backed background jobs & cron worker pack for upMVC (works standalone or with upmvc-saas-pack; zero Redis required).

Package info

github.com/upMVC/upMVC-Jobs-Pack

Homepage

pkg:composer/bitshost/upmvc-jobs-pack

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-28 19:41 UTC

This package is auto-updated.

Last update: 2026-11-28 19:44:19 UTC


README

Lightweight DB-backed background job queue & cron worker for any upMVC (^2.8) application — not SaaS-only.

Works standalone AND in SaaS: bitshost/upmvc-jobs-pack depends only on bitshost/upmvc (^2.8). It does not require bitshost/upmvc-saas-pack and registers no HTTP routes. Use it in single-tenant apps (CSV feed imports, async emails, PDF generation) or in multi-tenant upMVC-SaaS apps (by passing optional tenantId: $tenantId).

  • Zero Redis required — runs on standard MySQL/MariaDB (and SQLite for tests) on any VPS or shared host.
  • No forced HTTP surface — enqueue from PHP (JobQueue), run from cron/CLI (bin/upmvc-jobs-work.php).
  • Cron-safe by design — processes a bounded batch within a time budget (--max-seconds=50) and exits cleanly before the next cron tick.
  • Decoupled via upMVC 2.8 Events — emits jobs.done, jobs.retried, and jobs.failed.

Install

composer require bitshost/upmvc-jobs-pack

Register the provider in src/Etc/packages.php:

<?php

return [
    \BitsHost\UpmvcJobs\JobsServiceProvider::class,
];

Run migrations (applies database/migrations/001_jobs_layer.sql → table upmvc_jobs).

Usage

1. Register job handlers (during app boot / scripts/jobs-bootstrap.php)

use BitsHost\UpmvcJobs\Job;
use BitsHost\UpmvcJobs\JobRegistry;

JobRegistry::register('feed.import', function (array $payload, Job $job): void {
    // Process large CSV import, send async email, generate PDF, etc.
});

2. Enqueue a job from any controller or service

use BitsHost\UpmvcJobs\JobQueue;

$queue = JobQueue::fromDatabase();
$jobId = $queue->push(
    type: 'feed.import',
    payload: ['file' => 'storage/feeds/latest.csv'],
    queue: 'default',
    delaySeconds: 0,
    maxAttempts: 3,
    tenantId: null, // or (int) $tenantId in multi-tenant SaaS
);

3. Run the worker from cron (every minute)

* * * * * php /path/to/app/vendor/bitshost/upmvc-jobs-pack/bin/upmvc-jobs-work.php --bootstrap=/path/to/app/scripts/jobs-bootstrap.php --queue=default --max-jobs=50 --max-seconds=50 >> /var/log/upmvc-jobs.log 2>&1

4. Optional: react to job lifecycle via App\Etc\Events (upMVC 2.8+)

use App\Etc\Events;

Events::listen('jobs.failed', function (array $payload): void {
    error_log('Dead-letter job #' . $payload['id'] . ' (' . $payload['type'] . '): ' . ($payload['error'] ?? ''));
});

Local development

composer install
composer check   # PHPStan level 5 + PHPUnit (in-memory SQLite)