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

Resque Bundle Laravel Package

david-garcia/resque-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install Redis: Ensure Redis is running locally (redis-server) or configure a remote instance.
  2. Add Bundle: Require via Composer:
    composer require david-garcia/resque-bundle:^1.1
    
  3. Register Bundle: Add to AppKernel.php:
    new DavidGarciaCat\BCCResqueBundle\BCCResqueBundle(),
    
  4. Configure Redis: Update config.yml:
    bcc_resque:
        redis:
            host:     '127.0.0.1'
            port:     6379
            password: null
            database: 0
    

First Use Case: Enqueue a Job

  1. Create a Job Class:
    namespace AppBundle\Job;
    
    use BCC\ResqueBundle\Job\Job as BaseJob;
    
    class SendEmailJob extends BaseJob
    {
        public function perform($email, $message)
        {
            // Use Symfony services via $this->getContainer()
            $mailer = $this->getContainer()->get('mailer');
            $mailer->send(...);
        }
    }
    
  2. Enqueue the Job:
    $job = new SendEmailJob();
    $job->enqueue(['user@example.com', 'Hello!']);
    
    Or via command:
    php app/console bcc:resque:enqueue AppBundle:Job:SendEmailJob 'user@example.com' 'Hello!'
    

Implementation Patterns

Job Creation & Container Access

  • Extend BaseJob: All custom jobs must extend BCC\ResqueBundle\Job\Job.
  • Service Injection: Access Symfony services via $this->getContainer().
  • Parameter Handling: Pass arguments to perform() as an array.

Queue Management

  • Enqueue Jobs:
    $job->enqueueOn('critical', ['param1', 'param2']); // Custom queue
    
  • Worker Setup: Start workers via CLI:
    php app/console bcc:resque:worker default --verbose
    
    (Replace default with your queue name.)

Scheduling Jobs

  • Delayed Execution:
    $job->delay(3600); // Delay 1 hour (seconds)
    $job->at(new \DateTime('+1 day')); // Schedule for tomorrow
    

Monitoring

  • Dashboard: Access /_resque (configured route) to view:
    • Active queues.
    • Worker statuses.
    • Job history (basic).

Integration Tips

  • Symfony Events: Trigger jobs from event listeners:
    $job = new ProcessOrderJob();
    $job->enqueue([$orderId]);
    
  • Retry Logic: Use autoRequeue in config to retry failed jobs with backoff:
    bcc_resque:
        auto_requeue: true
        backoff_strategy: exponential
    

Gotchas and Tips

Pitfalls

  1. Redis Connection Issues:
    • Verify Redis is running (redis-cli ping).
    • Check database config in bcc_resque to avoid key collisions.
  2. Job Serialization:
    • Complex objects (e.g., Doctrine entities) won’t serialize by default. Use arrays or DTOs.
    • Example: Convert entity to array before enqueuing:
      $job->enqueue([$entity->getId(), $entity->getName()]);
      
  3. Worker Stuck on Jobs:
    • Kill workers gracefully with SIGTERM (not SIGKILL).
    • Check Redis for stuck jobs:
      redis-cli LRANGE resque:failed:count 0 -1
      

Debugging

  • Logs: Enable Symfony’s monolog to log job execution:
    monolog:
        handlers:
            resque:
                type: stream
                path: "%kernel.logs_dir%/resque.log"
                level: debug
    
  • Failed Jobs: Manually requeue failed jobs:
    php app/console bcc:resque:retry failed
    

Configuration Quirks

  • Queue Names: Must be alphanumeric (no special chars).
  • Worker Concurrency: Limit workers per queue to avoid Redis overload:
    bcc_resque:
        workers_per_queue: 2
    
  • Timezones: Schedule jobs in UTC to avoid timezone-related delays.

Extension Points

  1. Custom Job Classes: Override perform() for unique logic.
  2. Middleware: Extend BCC\ResqueBundle\Worker\Middleware\BaseMiddleware to add pre/post hooks.
  3. Dashboard Customization: Override Twig templates in Resources/views/BCCResqueBundle/.

Workarounds for TODOs

  • Job Status Tracking: Use Redis keys manually:
    redis-cli SET job:123 status "processing"
    
  • Localization: Manually inject translators via getContainer():
    $translator = $this->getContainer()->get('translator');
    
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.
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager