1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

heroku + laravel queue -- laravelキューをherokuで動かす

Last updated at Posted at 2020-10-21

TL;DR

heroku ps:scale worker=1
Procfile
web: vendor/bin/heroku-php-nginx -C nginx_app.conf public/
worker: php artisan queue:restart && php artisan queue:work database --tries=3

最強な良記事

実装

laravel側

routes/api.php
Route::post('queue-data',function(){
    $accessAt=now();
    $data=Str::random(10);
    \App\Jobs\StoreQueueData::dispatch($accessAt,$data)->delay(now()->addSeconds(3));
    return response()->json(['data' => $data,'access_at'=>$accessAt]);
});
app/Jobs/StoreQueueData.php
    public function handle()
    {
        $queue=QueueData::create([
            'data'=>$this->data,
            'access_at'=>$this->accessAt,
            'handle_at'=>now(),
        ]);
        Log::info('handle',['queue'=>$queue]);
    }

heroku設定

heroku ps:scale worker=1
Procfile
web: vendor/bin/heroku-php-nginx -C nginx_app.conf public/
worker: php artisan queue:restart && php artisan queue:work database --tries=3

動作確認

heroku-queue.png

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?