laravel jobs queue example

Example 1: how to automatically run queue in laravel

for queues with no queue name i.e. queue name = default
	php artisan queue:work 
  		or
	php artisan queue:listen
      
for jobs with a queue name. Let's assume i have a queue with name = sendemail

	php artisan queue:listen --queue=sendemail   
    
note: 
queue:work will only work for jobs entries currently in jobs table in database and stop.
queue:listen  will go on processing queues continously, both for current and new entries.

Example 2: laravel jobs

use Illuminate\Support\Facades\Redis;

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    Redis::throttle('key')->block(0)->allow(1)->every(5)->then(function () {
        info('Lock obtained...');

        // Handle job...
    }, function () {
        // Could not obtain lock...

        return $this->release(5);
    });
}

Tags:

Misc Example