Skip to content

Instantly share code, notes, and snippets.

@77web
Created December 19, 2020 04:16
Show Gist options
  • Save 77web/2b5399d2c5b9fac21b11ecf9b9022c74 to your computer and use it in GitHub Desktop.
Save 77web/2b5399d2c5b9fac21b11ecf9b9022c74 to your computer and use it in GitHub Desktop.
Laravelのキュー周りこういう書き方したらだめですかね?
<?php
namepace App\Jobs;
// 略
class FooJob implements ShouldQueue
{
private $param1;
private $param2;
public function __construct($param1, $param2)
{
$this->param1 = $param1;
$this->param2 = $param2;
}
public function handle(FooHandler $fooHandler)
{
$fooHandler->handle($this);
}
// 略
}
<?php
namespace App\Jobs\Handler;
// 略
class FooJobHandler
{
private $fooService;
public function __construct(FooService $fooService)
{
$this->fooService = $fooService;
}
public function handle(FooJob $job): void
{
// some more logic here
$this->fooService->foo($job->getParam1(), $job->getParam2());
// some more logic here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment