Last active
August 29, 2015 14:20
-
-
Save rodurma/89b7181e1810e38fe253 to your computer and use it in GitHub Desktop.
Exemplo de Command em Laravel + Queue + Delay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Commands; | |
use App\Commands\Command; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Bus\SelfHandling; | |
use Illuminate\Contracts\Queue\ShouldBeQueued; | |
class MeuComando extends Command implements SelfHandling, ShouldBeQueued { | |
use InteractsWithQueue, SerializesModels; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
// se command aqui... | |
} | |
/** | |
* Execute the command. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
// seu command aqui... | |
} | |
// https://github.com/laravel/framework/blob/5.0/src/Illuminate/Bus/Dispatcher.php#L237-L262 | |
public function queue($queue, $command) | |
{ | |
$queue->pushOn('fila', $command); | |
$queue->laterOn('pra_depois', 30, $command); // 30 segundos depois | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Handlers\Events; | |
use App\Events\MeuEvento; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldBeQueued; | |
class SendPasswordResetMailHandler implements ShouldBeQueued { | |
use InteractsWithQueue; | |
/** | |
* Create the event handler. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
// | |
} | |
/** | |
* Handle the event. | |
* | |
* @param PasswordWasChanged $event | |
* @return void | |
*/ | |
public function handle(MeuEvento $event) | |
{ | |
// seu evento aqui | |
} | |
// https://github.com/laravel/framework/blob/5.0/src/Illuminate/Events/Dispatcher.php#L422-L437 | |
public function queue($queue, $job, $args) | |
{ | |
$queue->push($job, $args, 'fila'); | |
$queue->laterOn('pra_depois', 30, $job, $args); // 30 segundos depois | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment