bitshost / upmvc-jobs-pack
Lightweight DB-backed background jobs & cron worker pack for upMVC (works standalone or with upmvc-saas-pack; zero Redis required).
Requires
- php: >=8.3
- bitshost/upmvc: ^2.8
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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-packdepends only onbitshost/upmvc(^2.8). It does not requirebitshost/upmvc-saas-packand registers no HTTP routes. Use it in single-tenant apps (CSV feed imports, async emails, PDF generation) or in multi-tenantupMVC-SaaSapps (by passing optionaltenantId: $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.8Events— emitsjobs.done,jobs.retried, andjobs.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)