Installation
composer require masando/edemy-backgroundbundle
Ensure eDemyFramework is installed and properly configured in your project.
Bundle Registration
Add to config/bundles.php:
Masando\eDemyBackgroundBundle\eDemyBackgroundBundle::class => ['all' => true],
First Use Case: Enqueue a Background Job
use Masando\eDemyBackgroundBundle\Background\BackgroundJob;
// In a controller or service
$job = new BackgroundJob('App\Jobs\ProcessUserData', ['userId' => 123]);
$this->get('edemy_background.job_dispatcher')->dispatch($job);
Check Configuration
Verify config/edemy_background.php exists (auto-generated) and adjust queue settings (e.g., default_queue, connection).
Job Dispatching
$dispatcher = $this->get('edemy_background.job_dispatcher');
$dispatcher->dispatch(new BackgroundJob('App\Jobs\SendEmail', ['email' => 'user@example.com']));
$dispatcher->dispatchMultiple([
new BackgroundJob('App\Jobs\GenerateReport', ['id' => 1]),
new BackgroundJob('App\Jobs\CleanupCache'),
]);
Job Definition
Extend Masando\eDemyBackgroundBundle\Background\AbstractJob for custom jobs:
namespace App\Jobs;
use Masando\eDemyBackgroundBundle\Background\AbstractJob;
class ProcessUserData extends AbstractJob {
public function handle() {
// Business logic here
}
}
Queue Integration
edemy_background.php:
'connection' => 'doctrine', // or 'messenger', 'sync'
'queue_name' => 'edemy_background',
Job Monitoring
BackgroundJobRepository to track jobs:
$jobs = $this->get('edemy_background.job_repository')->findBy(['status' => 'pending']);
kernel.request).
$eventDispatcher->addListener('kernel.request', function () use ($dispatcher) {
$dispatcher->dispatch(new BackgroundJob('App\Jobs\LogRequest'));
});
JobDispatcherInterface into services for reusable job handling.$this->mock('edemy_background.job_dispatcher')->shouldReceive('dispatch')->once();
Queue Connection Mismatch
edemy_background.php matches your actual queue setup (e.g., Doctrine Messenger requires MESSENGER_TRANSPORT_DSN in .env).php bin/console messenger:consume logs for connection errors.Job Serialization Issues
Serializable or use __serialize()/__unserialize().Missing Job Classes
BackgroundJob.composer dump-autoload).Race Conditions
$job = new BackgroundJob('App\Jobs\ProcessOrder', ['orderId' => 123], 'unique_job_123');
Enable Logging
Add to config/edemy_background.php:
'debug' => true,
Logs appear in var/log/dev.log.
Job Retries
Configure retry logic in AbstractJob:
protected $maxRetries = 3;
protected $delay = 60; // seconds
Queue Stuck? Clear pending jobs via:
php bin/console edemy_background:clear-queue
Custom Job Statuses
Extend the status field in the background_job table or override the JobRepository:
namespace App\Repository;
use Masando\eDemyBackgroundBundle\Repository\BackgroundJobRepository;
class CustomJobRepository extends BackgroundJobRepository {
// Add custom queries (e.g., 'failed_after_retries')
}
Middleware for Jobs
Add middleware to config/edemy_background.php:
'middleware' => [
App\Middleware\LogJobExecution::class,
],
Alternative Queue Drivers
Override the QueueFactory service to support custom drivers (e.g., Redis):
# config/services.yaml
Masando\eDemyBackgroundBundle\Queue\QueueFactory: ~
Webhooks for Job Events
Listen for job lifecycle events (e.g., job.started, job.failed) via Symfony’s event system:
$eventDispatcher->addListener(
'edemy_background.job.started',
[YourListener::class, 'onJobStarted']
);
How can I help you explore Laravel packages today?