/** * @param string $transactionName * @param CM_Cli_Command $command * @param CM_Cli_Arguments $arguments * @param CM_InputStream_Interface $streamInput * @param CM_OutputStream_Interface $streamOutput * @param CM_OutputStream_Interface $streamError * @return callable */ protected function _getProcessWorkload($transactionName, CM_Cli_Command $command, CM_Cli_Arguments $arguments, CM_InputStream_Interface $streamInput, CM_OutputStream_Interface $streamOutput, CM_OutputStream_Interface $streamError) { return function (CM_Process_WorkloadResult $result) use($transactionName, $command, $arguments, $streamInput, $streamOutput, $streamError) { try { $parameters = $command->extractParameters($arguments); $this->_checkUnusedArguments($arguments); if ($command->getKeepalive()) { CM_Service_Manager::getInstance()->getNewrelic()->ignoreTransaction(); } else { CM_Service_Manager::getInstance()->getNewrelic()->startTransaction($transactionName); } $command->run($parameters, $streamInput, $streamOutput, $streamError); } catch (CM_Cli_Exception_InvalidArguments $ex) { $this->_outputError('ERROR: ' . $ex->getMessage() . PHP_EOL); if (isset($command)) { $this->_outputError('Usage: ' . $arguments->getScriptName() . ' ' . $command->getHelp()); } else { $this->_outputError($this->getHelp()); } $result->setException($ex); } catch (CM_Cli_Exception_Internal $ex) { $this->_outputError('ERROR: ' . $ex->getMessage() . PHP_EOL); $result->setException($ex); } }; }