public function createProcessEngine(Configuration $config, LoggerInterface $logger = NULL) { $conn = $this->connectionManager->getConnection($config->getString('connection', 'default')); $transactional = $config->getBoolean('transactional', true); $dispatcher = $this->container->get(EventDispatcher::class); $engine = new ProcessEngine($conn, $dispatcher, $this->factory, $transactional); $engine->setDelegateTaskFactory($this->taskFactory); $engine->registerExecutionInterceptor(new ScopeExecutionInterceptor($this->scope)); $engine->setLogger($logger); $executor = new JobExecutor($engine, $this->scheduler); $this->container->eachMarked(function (JobHandler $handler, BindingInterface $binding) use($executor) { $executor->registerJobHandler($this->container->getBound($binding)); }); $engine->setJobExecutor($executor); $dispatcher->connect(function (AbstractProcessEvent $event) { $this->scope->enterContext($event->execution); }); $dispatcher->connect(function (TaskExecutedEvent $event) { $query = $event->engine->getRuntimeService()->createExecutionQuery(); $query->executionId($event->execution->getExecutionId()); $definition = $query->findOne()->getProcessDefinition(); $processKey = $definition->getKey(); $taskKey = $event->execution->getActivityId(); $this->container->eachMarked(function (TaskHandler $handler, BindingInterface $binding) use($event, $taskKey, $processKey) { if ($taskKey == $handler->taskKey) { if ($handler->processKey === NULL || $handler->processKey == $processKey) { $task = $this->container->getBound($binding); if (!$task instanceof TaskHandlerInterface) { throw new \RuntimeException('Invalid task handler implementation: ' . get_class($task)); } $task->executeTask($event->execution); } } }); }); return $engine; }