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

allprogrammic/resque-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require allprogrammic/resque-bundle
    

    Ensure ext-redis is enabled in your PHP environment.

  2. Configuration: Create a YAML config file (e.g., config/recurring_tasks.yml) with your recurring tasks:

    my_recurring_task:
        cron: "*/5 * * * *"  # Every 5 minutes
        class: App\Jobs\MyJob
        queue: default
        args: ["arg1", "arg2"]
        description: "Run every 5 minutes"
    
  3. Register the Bundle: Add to config/bundles.php (Symfony 4+):

    return [
        // ...
        AllProgrammic\ResqueBundle\AllProgrammicResqueBundle::class => ['all' => true],
    ];
    
  4. Run the Recurring Worker:

    php bin/console resque:recurring config/recurring_tasks.yml
    

First Use Case

Schedule a job to run every hour (e.g., a cleanup task):

cleanup_task:
    cron: "0 * * * *"
    class: App\Jobs\CleanupJob
    queue: cleanup
    description: "Daily cleanup at the start of every hour"

Implementation Patterns

Workflow Integration

  1. Job Creation: Extend Resque\Job or use Laravel-style job classes (if compatible). Example:

    namespace App\Jobs;
    use Resque\Job;
    
    class MyJob extends Job {
        protected $args;
    
        public function __construct($arg1, $arg2) {
            $this->args = [$arg1, $arg2];
        }
    
        public function perform() {
            // Logic here
        }
    }
    
  2. Queue Configuration:

    • Use Redis as the backend (configured via allprogrammic/redis-client).
    • Define queues in config/resque.php (if provided) or via bundle defaults.
  3. Dynamic Task Loading: Load tasks dynamically via CLI:

    php bin/console resque:recurring config/recurring_tasks_{env}.yml
    

    (Useful for environment-specific schedules.)

  4. Error Handling:

    • Log failures via SwiftmailerBundle (configured alerts).
    • Example alert config:
      # config/packages/swiftmailer.yaml
      swiftmailer:
          mailers:
              default:
                  transport: "%env(MAILER_DSN)%"
                  host: "%env(MAILER_HOST)%"
                  username: "%env(MAILER_USER)%"
                  password: "%env(MAILER_PASSWORD)%"
      
  5. Monitoring:

    • Use resque:workers to inspect active workers.
    • Log task execution in a database or file for auditing.

Common Patterns

  • Chaining Jobs: Trigger sequential jobs via MyJob::dispatch() inside another job.
  • Rate Limiting: Use cron expressions like */10 * * * * for every 10 minutes.
  • Environment Separation: Maintain recurring_tasks.yml and recurring_tasks_prod.yml.

Gotchas and Tips

Pitfalls

  1. Redis Connection Issues:

    • Ensure Redis server is running and accessible.
    • Debug with:
      redis-cli ping
      
    • Check allprogrammic/redis-client config for host/port/auth.
  2. Cron Syntax Errors:

    • Validate cron expressions using crontab.guru.
    • Example: * * * * * (every minute) vs. */5 * * * * (every 5 minutes).
  3. Job Class Not Found:

    • Verify the class path in YAML matches the fully qualified namespace (e.g., App\Jobs\MyJob).
    • Ensure the job class extends Resque\Job or is compatible.
  4. Swiftmailer Alerts:

    • If alerts fail, check:
      • SwiftmailerBundle is registered.
      • Mailer transport is configured (e.g., SMTP, Gmail).
      • No typos in MAILER_* env vars.
  5. Worker Stuck on Tasks:

    • Kill stuck workers with:
      pkill -f "php bin/console resque:work"
      
    • Restart workers after fixes.

Debugging Tips

  • Log Output: Run workers with verbose logging:
    php bin/console resque:work -v
    
  • Check Redis Queues: Inspect queues via Redis CLI:
    redis-cli LRANGE resque:queue:default 0 -1
    
  • Test Locally: Use resque:recurring with a small cron interval (e.g., */1 * * * *) for testing.

Extension Points

  1. Custom Job Classes: Override Resque\Job to add shared logic (e.g., logging, retries):

    namespace App\Jobs;
    use Resque\Job as BaseJob;
    
    class BaseAppJob extends BaseJob {
        public function onFailure($exception) {
            // Custom failure logic
        }
    }
    
  2. Dynamic Config Loading: Load YAML configs from multiple files:

    # config/recurring_tasks.yml
    imports:
        - { resource: recurring_tasks_common.yml }
        - { resource: recurring_tasks_prod.yml }
    
  3. Worker Hooks: Extend the worker class to add pre/post hooks:

    namespace App\Worker;
    use AllProgrammic\ResqueBundle\Worker\Worker as BaseWorker;
    
    class CustomWorker extends BaseWorker {
        protected function onStart() {
            // Pre-worker logic
        }
    }
    

    Register in config/services.yaml:

    services:
        App\Worker\CustomWorker:
            tags: ['resque.worker']
    
  4. Environment Variables: Use env vars for sensitive data (e.g., Redis password):

    # config/packages/all_programmic_resque.yaml
    all_programmic_resque:
        redis:
            password: "%env(REDIS_PASSWORD)%"
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware