| 1 | <?php |
||
| 11 | class ActionJob implements ShouldQueue |
||
| 12 | { |
||
| 13 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
| 14 | |||
| 15 | /** @var string */ |
||
| 16 | protected $actionClass; |
||
| 17 | |||
| 18 | /** @var array */ |
||
| 19 | protected $parameters; |
||
| 20 | |||
| 21 | public function __construct($action, array $parameters = []) |
||
| 22 | { |
||
| 23 | $this->actionClass = is_string($action) ? $action : get_class($action); |
||
| 24 | $this->parameters = $parameters; |
||
| 25 | |||
| 26 | $this->resolveQueueableProperties($action); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function displayName(): string |
||
| 30 | { |
||
| 31 | return $this->actionClass; |
||
| 32 | } |
||
| 33 | |||
| 34 | public function tags() |
||
| 35 | { |
||
| 36 | return ['action_job']; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function handle() |
||
| 40 | { |
||
| 41 | $action = app($this->actionClass); |
||
| 42 | |||
| 43 | $action->execute(...$this->parameters); |
||
| 44 | } |
||
| 45 | |||
| 46 | protected function resolveQueueableProperties($action) |
||
| 47 | { |
||
| 48 | $queueableProperties = [ |
||
| 49 | 'connection', |
||
| 50 | 'queue', |
||
| 51 | 'chainConnection', |
||
| 52 | 'chainQueue', |
||
| 53 | 'delay', |
||
| 54 | 'chained', |
||
| 55 | 'tries', |
||
| 56 | 'timeout', |
||
| 57 | ]; |
||
| 58 | |||
| 59 | foreach ($queueableProperties as $queueableProperty) { |
||
| 60 | if(property_exists($action, $queueableProperty) { |
||
| 61 | $this->{$queueableProperty} = $action->{$queueableProperty}; |
||
|
|
|||
| 62 | } |
||
| 66 |