ansien/simple-job-queue-bundle
Installation:
composer require ansien/simple-job-queue-bundle
Run migrations to create the sjqb_jobs table:
php bin/console doctrine:schema:update --force
First Job Creation:
Inject SimpleJobService and create a job:
use Ansien\SimpleJobQueueBundle\Service\SimpleJobService;
class MyController
{
public function __construct(private SimpleJobService $jobService) {}
public function enqueueJob()
{
$this->jobService->createJob('app:my-command', [
'param1' => 'value1',
'--option' => 'value2'
]);
}
}
Run Jobs Locally:
php bin/console simple-job-queue:run
config/packages/simple_job_queue.yaml (default config)src/Entity/Job.php (job entity structure)src/Service/SimpleJobService.php (core service)Command-Based Jobs:
$this->jobService->createJob('app:my-command', ['arg1' => 'value1']);
app: prefix for Symfony commands.Closure-Based Jobs (via custom entity extension):
$job = new Job();
$job->setCommand('my_closure_job');
$job->setPayload(json_encode(['data' => 'value']));
$job->setHandler(function ($payload) {
// Custom logic here
});
$em->persist($job);
$em->flush();
Delayed Jobs:
$this->jobService->createJob('app:delayed-command', [], 3600); // 1 hour delay
Dependency Injection:
# config/services.yaml
services:
App\Service\MyJobHandler:
tags: ['simple_job_queue.job_handler']
Implement Ansien\SimpleJobQueueBundle\Service\JobHandlerInterface.
Event Listeners:
use Ansien\SimpleJobQueueBundle\Event\JobEvent;
class MyJobListener implements JobHandlerInterface
{
public function handle(Job $job, JobEvent $event)
{
// Custom logic
}
}
Supervisor Configuration (as provided in README):
[program:simple_job_queue]
command=php %kernel.root_dir%/console simple-job-queue:run --env=prod --verbose
numprocs=4 # Adjust based on server capacity
Cron Alternative:
* * * * * php /path/to/bin/console simple-job-queue:run --env=prod >> /var/log/simple_job_queue.log 2>&1
Job Stuck in Queue:
sjqb_jobs table for status = 'pending'.'failed' and retry:
UPDATE sjqb_jobs SET status = 'failed' WHERE id = [job_id];
Command Not Found:
app: prefix for Symfony commands.Payload Serialization:
payload field uses JSON encoding. Ensure complex objects are serializable:
$payload = json_encode(['data' => $serializableObject]);
php bin/console simple-job-queue:run --verbose
tail -f /var/log/simple_job_queue.error.log
SELECT * FROM sjqb_jobs ORDER BY created_at DESC LIMIT 10;
Default Retry Logic:
max_retries in config/packages/simple_job_queue.yaml).Locking Mechanism:
LockFactory to prevent duplicate job execution.lock_ttl (default: 300 seconds) in config if jobs hang.Environment-Specific Settings:
# config/packages/simple_job_queue.yaml
simple_job_queue:
max_retries: 5
lock_ttl: 600 # 10 minutes
batch_size: 10 # Jobs processed per batch
Custom Job Handlers:
class CustomHandler implements JobHandlerInterface
{
public function handle(Job $job, JobEvent $event)
{
if ($job->getCommand() === 'custom:job') {
// Handle custom logic
}
}
}
Register in services.yaml with the simple_job_queue.job_handler tag.
Override Job Entity:
Extend Ansien\SimpleJobQueueBundle\Entity\Job and update the entity manager mapping.
Custom Storage:
Override the JobRepository to use a different database or storage backend (e.g., Redis).
How can I help you explore Laravel packages today?