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

Laravel Queue Snssqs Laravel Package

mtahv3/laravel-queue-snssqs

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer:

composer require vendor/package-name

The package now fully supports Laravel 8.x, including native job features like tries, retryUntil, backoff, batch, timeout, and maxExceptions. For first use, check the updated docs for Laravel 8 compatibility and test with a simple job:

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ExampleJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        // Job logic
    }

    // New Laravel 8 features
    public function retryUntil()
    {
        return now()->addMinutes(5);
    }

    public function backoff()
    {
        return 10; // seconds
    }
}

Dispatch via dispatch() or dispatchNow().


Implementation Patterns

Leveraging Native Laravel 8 Job Features

  1. Retry Logic: Use retryUntil() to dynamically set retry deadlines (e.g., for transient failures).

    public function retryUntil()
    {
        return now()->addMinutes($this->maxRetries * 2);
    }
    
  2. Exponential Backoff: Implement backoff() to delay retries exponentially (e.g., for rate-limited APIs).

    public function backoff()
    {
        return $this->attempts() * 1000; // Milliseconds
    }
    
  3. Batch Processing: Use batch() to group jobs (e.g., for bulk operations).

    ExampleJob::dispatch($data)->batch(ExampleJob::class);
    
  4. Timeouts: Set timeout() to fail jobs after inactivity (default: 60 seconds).

    public function timeout()
    {
        return 300; // Seconds
    }
    
  5. Exception Handling: Limit failures with maxExceptions() (e.g., for non-recoverable errors).

    public function maxExceptions()
    {
        return 3;
    }
    

Integration Workflow

  • Queue Workers: Ensure your queue worker (php artisan queue:work) is running with --sleep=3 for optimal backoff handling.
  • Middleware: Extend job middleware (e.g., HandleFailures) to log retries or trigger alerts.
  • Monitoring: Use Laravel Horizon or queue:failed to track job progress and failures.

Gotchas and Tips

Breaking Changes (8.0.0)

  • Laravel 7.x Dropped: This version requires Laravel 8.x. Upgrade via:
    composer require laravel/framework:^8.0
    
  • Job Class Changes: If extending ShouldQueue, ensure all traits (Dispatchable, InteractsWithQueue, etc.) are updated to Laravel 8’s versions.

Debugging Tips

  1. Retry Loops:

    • Check failed_jobs table for retry attempts. Use queue:flush to clear stale jobs during testing.
    • Log attempts() in handle() to verify retry counts:
      \Log::info("Attempt #{$this->attempts()}");
      
  2. Backoff Delays:

    • Test locally with QUEUE_CONNECTION=sync to bypass delays, then switch to database/redis for real backoff behavior.
  3. Batch Quirks:

    • Batches share the same job payload. Use onQueue() to separate critical batches:
      ExampleJob::dispatch()->onQueue('high_priority')->batch(ExampleJob::class);
      

Extension Points

  • Custom Retry Logic: Override retryUntil() dynamically (e.g., based on job payload):

    public function retryUntil()
    {
        return $this->payload['retryDeadline'] ?? now()->addMinute();
    }
    
  • Queue Events: Listen for job.processing, job.failed, or job.released events to hook into the retry lifecycle:

    event(new JobProcessing(ExampleJob::class, $job));
    
  • Testing: Use Queue::fake() with assertProcessed()/assertFailed() to verify retries:

    $job = ExampleJob::dispatch();
    Queue::fake();
    $job->fail(new \Exception('Test'));
    Queue::assertProcessed(ExampleJob::class);
    
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.
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
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