Push notifications to queue (fix #78)

This commit is contained in:
Pig Fang 2019-07-05 22:48:23 +08:00
parent 2eb4f4e2d4
commit 4529d1e219
9 changed files with 65 additions and 5 deletions

View File

@ -66,7 +66,7 @@ MAIL_ENCRYPTION = null
# Change below lines only if you know what they mean!
CACHE_DRIVER = file
SESSION_DRIVER = file
QUEUE_DRIVER = sync
QUEUE_DRIVER = database
REDIS_HOST = 127.0.0.1
REDIS_PASSWORD = null

View File

@ -4,10 +4,14 @@ declare(strict_types=1);
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
class SiteMessage extends Notification
class SiteMessage extends Notification implements ShouldQueue
{
use Queueable;
public $title;
public $content;

View File

@ -50,8 +50,11 @@ class AppServiceProvider extends ServiceProvider
try {
if (option('enable_redis') && Redis::ping()) {
config(['cache.default' => 'redis']);
config(['session.driver' => 'redis']);
config([
'cache.default' => 'redis',
'session.driver' => 'redis',
'queue.default' => 'redis',
]);
}
} catch (\Exception $e) {
//

View File

@ -15,7 +15,7 @@ return [
|
*/
'default' => env('QUEUE_DRIVER', 'sync'),
'default' => env('QUEUE_DRIVER', 'database'),
/*
|--------------------------------------------------------------------------

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}

View File

@ -0,0 +1,10 @@
<?php
return [
'请您手动打开终端或 PowerShell 执行以下命令以完成升级:',
'Please open terminal or PowerShell to complete upgrade:',
'<code>php artisan migrate --force</code>',
'',
'然后修改 .env 文件,将 <code>QUEUE_DRIVER</code> 的值改为 <code>database</code>。(使用 Redis 的用户请修改为 <code>redis</code>',
'Then, please edit your ".env" file. Change the value of <code>QUEUE_DRIVER</code> from <code>sync</code> to <code>database</code>. Redis users please change it to <code>redis</code>.',
];

View File

@ -0,0 +1,3 @@
## Tweaked
- Push notifications to queue for performance.

View File

@ -0,0 +1,3 @@
## 调整
- 发送通知时将任务推送到队列

View File

@ -41,6 +41,7 @@ class SetupControllerTest extends TestCase
'oauth_personal_access_clients',
'oauth_refresh_tokens',
'notifications',
'jobs',
];
array_walk($tables, function ($table) {
Schema::dropIfExists($table);