Skip to content

Commit ee73f3a

Browse files
committed
Update dispatch logic for actions
1 parent b6f739c commit ee73f3a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Traits/ManagesExecution.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Safemood\Workflow\Traits;
44

5-
use Illuminate\Contracts\Queue\ShouldQueue;
5+
use Illuminate\Foundation\Bus\Dispatchable as DispatchableJob;
6+
use Illuminate\Foundation\Events\Dispatchable as DispatchableEvent;
67
use Safemood\Workflow\Enums\ActionState;
78

89
trait ManagesExecution
@@ -75,8 +76,8 @@ protected function executeActions(array $actions, array &$context)
7576
$this->initializeActionState($action);
7677

7778
try {
78-
if ($this->isJobAction($action)) {
79-
$this->dispatchJob($action, $context);
79+
if ($this->isDispatchable($action)) {
80+
$this->dispatchAction($action, $context);
8081
} else {
8182
$this->handleAction($action, $context);
8283
}
@@ -99,13 +100,18 @@ protected function handleAction($action, array &$context)
99100
$action->handle($context);
100101
}
101102

102-
protected function isJobAction($action): bool
103+
protected function isDispatchable($action): bool
103104
{
105+
$traits = class_uses($action);
106+
107+
return ! empty(array_intersect($traits, [
108+
DispatchableJob::class,
109+
DispatchableEvent::class,
110+
]));
104111

105-
return $action instanceof ShouldQueue;
106112
}
107113

108-
protected function dispatchJob($action, array &$context): void
114+
protected function dispatchAction($action, array &$context): void
109115
{
110116

111117
$action::dispatch($context);

0 commit comments

Comments
 (0)