Installation
composer require bnza/job-manager
Register the bundle in config/bundles.php:
return [
// ...
Bnza\JobManagerBundle\JobManagerBundle::class => ['all' => true],
];
Basic Configuration
Define job types in config/packages/bnza_job_manager.yaml:
bnza_job_manager:
jobs:
my_job:
class: App\Job\MyJob
command: 'app:my-job'
description: 'Processes user data'
First Job Class
Create a job class (e.g., src/Job/MyJob.php):
namespace App\Job;
use Bnza\JobManagerBundle\Job\JobInterface;
class MyJob implements JobInterface {
public function execute() {
// Job logic here
return true;
}
}
Run via CLI
php bin/console job:run my_job
job:queue command to add a job to the queue.
php bin/console job:queue my_job --data='{"user_id": 123}'
job:list.Job Execution Flow
job:queue → Stores job in DB (via JobQueue entity).job:run → Fetches jobs from DB, executes them sequentially, and logs results.job:retry <job_id>.Data Handling
--data CLI argument (JSON-serialized).JobInterface::getData():
$userId = $this->getData()['user_id'];
Logging
JobLog entity (auto-created on job completion/failure).job:logs or query the job_log table.Symfony Commands
Extend Bnza\JobManagerBundle\Command\JobCommand for custom job-specific commands.
Example:
namespace App\Command;
use Bnza\JobManagerBundle\Command\JobCommand;
class CustomJobCommand extends JobCommand {
protected function configure() {
$this->setName('app:custom-job');
}
}
Event Listeners
Hook into job lifecycle events (e.g., JobEvents::JOB_STARTED):
# config/services.yaml
services:
App\EventListener\JobListener:
tags:
- { name: kernel.event_listener, event: bnza.job_manager.job.started, method: onJobStarted }
Database Schema
The bundle auto-creates tables (job_queue, job_log). Customize via migrations or Doctrine extensions.
Job Data Serialization
--data must be valid JSON. Non-serializable objects (e.g., closures) will fail.json_encode() on arrays/objects before passing via CLI.Command Naming Collisions
command in job_manager.yaml matches your Symfony command name.php bin/console list after configuration.Locking Issues
JobQueue::lock()). Long-running jobs may timeout.job:run --timeout=3600 to adjust the lock duration (default: 300s).Logging Overwrite
job_log table. Custom log handlers may overwrite data.JobLog entity or override the JobLogger service.Check Queue Status
php bin/console job:list --all
pending: Not yet run.running: Locked by another process.failed: Execution threw an exception.Inspect Job Data Dump job data in the job class:
var_dump($this->getData());
Enable Debug Mode
Set BNZA_JOB_MANAGER_DEBUG=1 in .env to log additional details.
Custom Job Storage
Override the job_queue table by extending the JobQueue entity or using a custom repository.
Parallel Execution The bundle runs jobs sequentially. For parallelism:
job:queue.GUI Integration
use Bnza\JobManagerBundle\Entity\JobQueue;
public function showJobs() {
return $this->render('jobs/index.html.twig', [
'jobs' => $this->getDoctrine()->getRepository(JobQueue::class)->findAll(),
]);
}
Scheduled Jobs
Combine with Symfony’s CronBundle or Laravel’s task scheduling:
# config/packages/cron.yaml
cron:
jobs:
daily_job:
command: 'job:run my_job'
schedule: '0 0 * * *'
How can I help you explore Laravel packages today?