16
16
use Symfony \Component \Console \Input \InputInterface ;
17
17
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
18
18
use Symfony \Component \Console \Output \OutputInterface ;
19
+ use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
20
+ use Task \Event \Events ;
21
+ use Task \Event \TaskEvent ;
19
22
use Task \Executor \FailedException ;
20
23
use Task \Handler \TaskHandlerFactoryInterface ;
21
24
use Task \Storage \TaskExecutionRepositoryInterface ;
@@ -35,6 +38,11 @@ class ExecuteCommand extends Command
35
38
*/
36
39
private $ executionRepository ;
37
40
41
+ /**
42
+ * @var EventDispatcherInterface
43
+ */
44
+ private $ eventDispatcher ;
45
+
38
46
/**
39
47
* @param string $name
40
48
* @param TaskHandlerFactoryInterface $handlerFactory
@@ -43,12 +51,14 @@ class ExecuteCommand extends Command
43
51
public function __construct (
44
52
$ name ,
45
53
TaskHandlerFactoryInterface $ handlerFactory ,
46
- TaskExecutionRepositoryInterface $ executionRepository
54
+ TaskExecutionRepositoryInterface $ executionRepository ,
55
+ EventDispatcherInterface $ dispatcher
47
56
) {
48
57
parent ::__construct ($ name );
49
58
50
59
$ this ->handlerFactory = $ handlerFactory ;
51
60
$ this ->executionRepository = $ executionRepository ;
61
+ $ this ->eventDispatcher = $ dispatcher ;
52
62
}
53
63
54
64
/**
@@ -70,7 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
70
80
$ handler = $ this ->handlerFactory ->create ($ execution ->getHandlerClass ());
71
81
72
82
try {
83
+ $ this ->eventDispatcher ->dispatch (new TaskEvent ($ execution ->getTask ()),Events::TASK_BEFORE );
73
84
$ result = $ handler ->handle ($ execution ->getWorkload ());
85
+ $ this ->eventDispatcher ->dispatch (new TaskEvent ($ execution ->getTask ()),Events::TASK_BEFORE );
74
86
} catch (\Exception $ exception ) {
75
87
if ($ exception instanceof FailedException) {
76
88
$ errorOutput ->writeln (FailedException::class);
0 commit comments