Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Simple Job Queue Bundle Laravel Package

ansien/simple-job-queue-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require ansien/simple-job-queue-bundle
    

    Run migrations to create the sjqb_jobs table:

    php bin/console doctrine:schema:update --force
    
  2. 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'
            ]);
        }
    }
    
  3. Run Jobs Locally:

    php bin/console simple-job-queue:run
    

Key Files to Review

  • config/packages/simple_job_queue.yaml (default config)
  • src/Entity/Job.php (job entity structure)
  • src/Service/SimpleJobService.php (core service)

Implementation Patterns

Job Creation Workflows

  1. Command-Based Jobs:

    $this->jobService->createJob('app:my-command', ['arg1' => 'value1']);
    
    • Use app: prefix for Symfony commands.
    • Pass arguments as an associative array.
  2. 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();
    
  3. Delayed Jobs:

    $this->jobService->createJob('app:delayed-command', [], 3600); // 1 hour delay
    

Integration with Symfony Services

  • 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
        }
    }
    

Production Deployment

  • 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
    

Gotchas and Tips

Common Pitfalls

  1. Job Stuck in Queue:

    • Check sjqb_jobs table for status = 'pending'.
    • Manually update status to 'failed' and retry:
      UPDATE sjqb_jobs SET status = 'failed' WHERE id = [job_id];
      
  2. Command Not Found:

    • Ensure the command is registered in Symfony’s kernel.
    • Verify the app: prefix for Symfony commands.
  3. Payload Serialization:

    • The payload field uses JSON encoding. Ensure complex objects are serializable:
      $payload = json_encode(['data' => $serializableObject]);
      

Debugging Tips

  • Enable Verbose Mode:
    php bin/console simple-job-queue:run --verbose
    
  • Check Logs:
    tail -f /var/log/simple_job_queue.error.log
    
  • Database Inspection:
    SELECT * FROM sjqb_jobs ORDER BY created_at DESC LIMIT 10;
    

Configuration Quirks

  1. Default Retry Logic:

    • Retries are handled automatically (configurable via max_retries in config/packages/simple_job_queue.yaml).
    • Default: 3 retries with exponential backoff.
  2. Locking Mechanism:

    • Uses Symfony’s LockFactory to prevent duplicate job execution.
    • Adjust lock_ttl (default: 300 seconds) in config if jobs hang.
  3. 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
    

Extension Points

  1. 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.

  2. Override Job Entity: Extend Ansien\SimpleJobQueueBundle\Entity\Job and update the entity manager mapping.

  3. Custom Storage: Override the JobRepository to use a different database or storage backend (e.g., Redis).

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope