lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

Stop running action if run as Job #188

Closed metallurgical closed 2 years ago

metallurgical commented 2 years ago

Hi, may i know, is there any method that i can check the logic (return true or false) before job further running like instance without doing inside handle():

public function shouldCancel()
{
  // Logic
 return true; // false
}
leandrodiogenes commented 2 years ago

Hi @metallurgical, I believe the validation would be appropriate for your case, but it needs to be done inside the handle. In my point of view, laravel-actions are generic tasks. The handle method is responsable to execute the task. If you want to validate before the handle method, you can create an validation on asJob method.

    public function asJob(Team $team): void
    {
       //Logic to handle or not
        $this->handle($team, true);
    }

But that validation logic applies only to job executions.

metallurgical commented 2 years ago

@leandrodiogenes ok i get what you mean. asJob would be more appropriate place to do seems i dont want to messed up handle method and i use this action file specifically for job. Thanks for the tips