* Use queues for notifications #1154 * Styles * Update defaults * Include queueworker
This commit is contained in:
32
app/Console/Commands/EmailTest.php
Normal file
32
app/Console/Commands/EmailTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App;
|
||||
use App\Contracts\Command;
|
||||
|
||||
class EmailTest extends Command
|
||||
{
|
||||
protected $signature = 'phpvms:email-test';
|
||||
protected $description = 'Send a test notification to admins';
|
||||
|
||||
/**
|
||||
* Run dev related commands
|
||||
*
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/** @var App\Notifications\EventHandler $eventHandler */
|
||||
$eventHandler = app(App\Notifications\EventHandler::class);
|
||||
|
||||
$news = new App\Models\News();
|
||||
$news->user_id = 1;
|
||||
$news->subject = 'Test News';
|
||||
$news->body = 'Test Body';
|
||||
$news->save();
|
||||
|
||||
$newsEvent = new App\Events\NewsAdded($news);
|
||||
$eventHandler->onNewsAdded($newsEvent);
|
||||
}
|
||||
}
|
||||
38
app/Console/Commands/ProcessQueue.php
Normal file
38
app/Console/Commands/ProcessQueue.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App;
|
||||
use App\Contracts\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ProcessQueue extends Command
|
||||
{
|
||||
protected $signature = 'queue:cron';
|
||||
protected $description = 'Process the queue from a cron job';
|
||||
|
||||
/**
|
||||
* Run the queue tasks
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Artisan::call('queue:work', [
|
||||
'--sansdaemon' => null,
|
||||
'--stop-when-empty' => null,
|
||||
]);
|
||||
|
||||
Log::info(Artisan::output());
|
||||
///** @var App\Support\WorkCommand $queueWorker */
|
||||
//$queueWorker = new App\Support\WorkCommand(app('queue.worker'), app('cache.store'));
|
||||
|
||||
//$queueWorker->setInput($queueWorker->createInputFromArguments([]));
|
||||
//$queueWorker->handle();
|
||||
|
||||
/*$output = $this->call('queue:work', [
|
||||
'--stop-when-empty' => null,
|
||||
]);
|
||||
|
||||
Log::info($output);*/
|
||||
}
|
||||
}
|
||||
25
app/Console/Cron/JobQueue.php
Normal file
25
app/Console/Cron/JobQueue.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Cron;
|
||||
|
||||
use App\Contracts\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
/**
|
||||
* This just calls the CronHourly event, so all of the
|
||||
* listeners, etc can just be called to run those tasks
|
||||
*/
|
||||
class JobQueue extends Command
|
||||
{
|
||||
protected $signature = 'cron:queue';
|
||||
protected $description = 'Run the cron queue tasks';
|
||||
protected $schedule;
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$this->redirectLoggingToFile('cron');
|
||||
Artisan::call('queue:cron');
|
||||
|
||||
$this->info(Artisan::output());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Cron\Hourly;
|
||||
use App\Console\Cron\JobQueue;
|
||||
use App\Console\Cron\Monthly;
|
||||
use App\Console\Cron\Nightly;
|
||||
use App\Console\Cron\Weekly;
|
||||
@@ -25,6 +26,10 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
$schedule->command(JobQueue::class)
|
||||
->everyMinute()
|
||||
->withoutOverlapping();
|
||||
|
||||
$schedule->command(Nightly::class)->dailyAt('01:00');
|
||||
$schedule->command(Weekly::class)->weeklyOn(0);
|
||||
$schedule->command(Monthly::class)->monthlyOn(1);
|
||||
|
||||
@@ -24,9 +24,9 @@ abstract class Command extends \Illuminate\Console\Command
|
||||
parent::__construct();
|
||||
|
||||
// Running in the console but not in the tests
|
||||
if (app()->runningInConsole() && env('APP_ENV') !== 'testing') {
|
||||
/*if (app()->runningInConsole() && env('APP_ENV') !== 'testing') {
|
||||
$this->redirectLoggingToFile('stdout');
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
22
app/Listeners/MessageLoggedListener.php
Normal file
22
app/Listeners/MessageLoggedListener.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Log\Events\MessageLogged;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
/**
|
||||
* Show logs in the console
|
||||
*
|
||||
* https://stackoverflow.com/questions/48264479/log-laravel-with-artisan-output
|
||||
*/
|
||||
class MessageLoggedListener
|
||||
{
|
||||
public function handle(MessageLogged $event)
|
||||
{
|
||||
if (app()->runningInConsole()) {
|
||||
$output = new ConsoleOutput();
|
||||
$output->writeln("<$event->level>$event->message</$event->level>");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,11 @@ namespace App\Models;
|
||||
use App\Contracts\Model;
|
||||
|
||||
/**
|
||||
* @property string subject
|
||||
* @property string body
|
||||
* @property int id
|
||||
* @property int|mixed user_id
|
||||
* @property string subject
|
||||
* @property string body
|
||||
* @property User user
|
||||
*/
|
||||
class News extends Model
|
||||
{
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class AdminUserRegistered extends Notification
|
||||
class AdminUserRegistered extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\News;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class NewsAdded extends Notification
|
||||
class NewsAdded extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,12 +5,15 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
/**
|
||||
* Send the PIREP accepted message to a particular user
|
||||
*/
|
||||
class PirepAccepted extends Notification
|
||||
class PirepAccepted extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class PirepRejected extends Notification
|
||||
class PirepRejected extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class PirepSubmitted extends Notification
|
||||
class PirepSubmitted extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class UserPending extends Notification
|
||||
class UserPending extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class UserRegistered extends Notification
|
||||
class UserRegistered extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -5,9 +5,12 @@ namespace App\Notifications\Messages;
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class UserRejected extends Notification
|
||||
class UserRejected extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
|
||||
@@ -39,6 +39,11 @@ class EventServiceProvider extends ServiceProvider
|
||||
|
||||
UpdateAvailable::class => [],
|
||||
UpdateSucceeded::class => [],
|
||||
|
||||
// Log messages out to the console if running there
|
||||
'Illuminate\Log\Events\MessageLogged' => [
|
||||
'App\Listeners\MessageLoggedListener',
|
||||
],
|
||||
];
|
||||
|
||||
protected $subscribe = [
|
||||
|
||||
Reference in New Issue
Block a user