Closed edalzell closed 1 year ago
Saw this asked in another issue. The solution is to use the asJob()
method
https://github.com/lorisleiva/laravel-actions/issues/158#issuecomment-1024735186
Saw this asked in another issue. The solution is to use the
asJob()
method
How can I fail the job when it's running though, which will be in the handle method, likely?
The as....
methods are only called on instantiation, I need access when the task is running.
I figured you would use the asJob()
and then pass that job itself to the handle like:
public function asJob(JobDecorator $job)
{
$this->handle($job);
}
But I'm trying right now and can't get it to work.
Hi there,
The as.... methods are only called on instantiation
@edalzell This is not true, the asJob
method, just like the handle
method, is called at runtime. See code below.
As you can see, both resolve parameters using the getPrependedParameters
method which will pass in the JobDecorator
if it is type-hinted. So you could even do the following, should you only need your action as a job.
public function handle(JobDecorator $job)
{
// ...
$job->fail();
}
But I'm trying right now and can't get it to work.
@chris-sev Your code should work. Could you let me know the error / unexpected behaviour you are getting? Brownie points for a PR that provides a regression test. 🙃
Oh thanks, I didn’t know that!
Closing cuz it looks like I can do it, thanks!
I need to manually fail a job/action, but I can't call
$this->fail
like I could on a "real" job.Can you please add this?