Installation:
composer require aureja/job-queue-bundle "dev-master"
Add the bundle to AppKernel.php under registerBundles().
Entity Setup:
Extend Aureja\JobQueue\Model\JobReport and Aureja\JobQueue\Model\JobConfiguration in your src/ directory (e.g., src/Acme/YourBundle/Entity/). Example:
// src/Acme/YourBundle/Entity/JobReport.php
namespace Acme\YourBundle\Entity;
use Aureja\JobQueue\Model\JobReport as BaseJobReport;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="aureja_job_report")
*/
class JobReport extends BaseJobReport { ... }
Configuration:
Update config.yml with your entity classes and queues:
aureja_job_queue:
db_driver: orm
class:
model:
job_configuration: Acme\YourBundle\Entity\JobConfiguration
job_report: Acme\YourBundle\Entity\JobReport
queues:
- default
Database Schema:
Run php app/console doctrine:schema:update --force to create tables.
Routing:
Import routes in routing.yml:
aureja_job_queue:
resource: "@AurejaJobQueueBundle/Resources/config/routing.xml"
First Job: Enqueue a job via the CLI or a controller:
php app/console aureja:job-queue:enqueue Acme\YourBundle\Command\YourJobCommand
Job Enqueuing:
Use the enqueue command to dispatch jobs to queues:
php app/console aureja:job-queue:enqueue Acme\YourBundle\Command\ProcessUserCommand --queue=default --data='{"user_id": 1}'
--data.--queue (e.g., high_priority).Job Processing: Register a cronjob to run the worker every minute:
* * * * * php app/console aureja:job-queue:run
aureja:job-queue:run ad-hoc for testing.Job Monitoring: Use the admin interface (auto-routed) to:
Custom Job Logic:
Extend Aureja\JobQueue\Model\Job or implement Aureja\JobQueue\Model\JobInterface:
namespace Acme\YourBundle\Job;
use Aureja\JobQueue\Model\Job as BaseJob;
class ProcessUserJob extends BaseJob {
public function execute() {
// Custom logic (e.g., fetch user from DB, process data).
return $this->success(); // or $this->fail('Error message');
}
}
Configuration Management:
JobConfiguration.config.yml without code changes.Symfony Commands: Dispatch jobs from commands:
use Aureja\JobQueueBundle\Command\EnqueueCommand;
$enqueue = $this->getContainer()->get('aureja.job_queue.enqueue');
$enqueue->enqueue('Acme\YourBundle\Job\ProcessUserJob', ['user_id' => 1], 'default');
Events:
Listen for job lifecycle events (e.g., job.enqueued, job.failed) via Symfony’s event dispatcher.
Testing:
JobQueue service in PHPUnit:
$jobQueue = $this->getMockBuilder('Aureja\JobQueue\JobQueue')
->disableOriginalConstructor()
->getMock();
$this->container->set('aureja.job_queue', $jobQueue);
aureja:job-queue:clear to reset test data.Performance:
JobConfiguration::setBatchSize().critical).Cronjob Misconfiguration:
www-data for Symfony).php app/console aureja:job-queue:run --env=dev.Entity Mapping Issues:
JobReport/JobConfiguration, ensure all @ORM\ annotations match the base class.Aureja\JobQueue\Model\JobReport annotations.Queue Locking:
JobConfiguration::setTimeout() to auto-release locks.Data Serialization:
Database Driver:
orm. For custom drivers (e.g., MongoDB), implement Aureja\JobQueue\Driver\DriverInterface.Log Output:
Enable debug mode (APP_DEBUG=true) to see job execution logs in var/log/dev.log.
Admin Panel:
queue or status (e.g., failed).Command-Line Flags:
--dry-run:
php app/console aureja:job-queue:run --dry-run
php app/console aureja:job-queue:run -v
Common Errors:
JobInterface and is autoloaded.php app/console doctrine:schema:validate to check entity mappings.Custom Drivers:
Implement Aureja\JobQueue\Driver\DriverInterface for non-Doctrine storage (e.g., Redis):
class RedisDriver implements DriverInterface {
public function save(JobReport $report) { ... }
public function findPending() { ... }
}
Register in services.yml:
aureja.job_queue.driver: '@your.redis_driver'
Job Middleware:
Add pre/post-processing logic by extending Aureja\JobQueue\JobQueue and overriding executeJob().
Event Listeners:
Subscribe to job events (e.g., job.failed) to trigger alerts or retries:
// src/Acme/YourBundle/EventListener/JobListener.php
namespace Acme\YourBundle\EventListener;
use Aureja\JobQueue\Event\JobEvent;
class JobListener {
public function onJobFailed(JobEvent $event) {
// Send Slack notification, etc.
}
}
Register in services.yml:
services:
acme.job_listener:
class: Acme\YourBundle\EventListener\JobListener
tags:
- { name: kernel.event_listener, event: job.failed, method: onJobFailed }
Custom Job Statuses:
Extend the status field in JobReport (e.g., processing, retrying) and update the admin template.
How can I help you explore Laravel packages today?