Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Created August 31, 2016 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudiedirkx/572462c1b96b0353431918a709630fe2 to your computer and use it in GitHub Desktop.
Save rudiedirkx/572462c1b96b0353431918a709630fe2 to your computer and use it in GitHub Desktop.
User invitation jobs
<?php
class SendUserInvitationJob {
protected $user;
protected $tests;
function __construct(User $user, array $tests) {
$this->user = $user;
$this->tests = $tests;
}
function handle(Mailer $mailer) {
$mailer->sendTo($this->user, 'invitation');
}
}
<?php
class SendUserInvitationReminderJob extends SendUserInvitationJob {
function handle(Mailer $mailer) {
$mailer->sendTo($this->user, 'invitation reminder');
}
}
<?php
class UserController {
function postCreate(Queue $queue) {
$user = new User;
$tests = [new Test, new Test];
$queue->dispatch(new SendUserInvitationJob($user, $tests)); // instantly
$queue->dispatch((new SendUserInvitationReminderJob($user, $tests))->delay('1 week')); // later
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment