action = $action; $this->method = $method; $this->fields = $fields; $this->models = $models; $this->batchId = $batchId; } /** * Execute the job. * * @return void */ public function handle() { return $this->callAction(function ($action) { return $action->withBatchId($this->batchId)->{$this->method}($this->fields, $this->models); }); } /** * Call the failed method on the job instance. * * @param \Exception $e * @return void */ public function failed($e) { Nova::actionEvent()->markBatchAsFailed($this->batchId, $e); if ($method = $this->failedMethodName()) { call_user_func([$this->action, $method], $this->fields, $this->models, $e); } } /** * Get the name of the "failed" method that should be called for the action. * * @return string|null */ protected function failedMethodName() { if (($method = $this->failedMethodForModel()) && method_exists($this->action, $method)) { return $method; } return method_exists($this->action, 'failed') ? 'failed' : null; } /** * Get the appropriate "failed" method name for the action's model type. * * @return string|null */ protected function failedMethodForModel() { if ($this->models->isNotEmpty()) { return 'failedFor'.Str::plural(class_basename($this->models->first())); } } }