LoginSignup
2
4

More than 5 years have passed since last update.

「キュー(Queue)」、Laravel「処理の待ち行列」

Posted at
  • 「キュー(Queue)」とは「処理の待ち行列」である
  • キューサービスには「データ投入」と「データ取出」の処理が求められる
  • 「高い応答速度」「高い耐久性」
  • 例:Beanstalk、Amazon SQS、Redis

laravel queue

データベースに記録ファイルを作成(必要)
php artisan queue:table
php artisan migrate

依存パッケージ

Amazon SQS: aws/aws-sdk-php ~3.0
Beanstalkd: pda/pheanstalk ~3.0
Redis: predis/predis ~1.0

Redisの設定

#config/database.php
'redis' => [
    'driver' => 'redis',
    'connection' => 'default',
    'queue' => '{default}',
    'retry_after' => 90,
],
//jobを作成
php artisan make:job SendReminderEmail
#app/jobs/ProcessPodcast.php
<?php

namespace App\Jobs;

use App\Podcast;
use App\AudioProcessor;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $podcast;

    /**
     * 新しいジョブインスタンスの生成
     *
     * @param  Podcast  $podcast
     * @return void
     */
    public function __construct(Podcast $podcast)
    {
        $this->podcast = $podcast;
    }

    /**
     * ジョブの実行
     *
     * @param  AudioProcessor  $processor
     * @return void
     */
    public function handle(AudioProcessor $processor)
    {
        // アップロード済みポッドキャストの処理…
    }
}

参考:
https://readouble.com/laravel/5.4/ja/queues.html

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4