/** * @param $message * @param array $extra * * @return $this */ public function debug($message, $extra = []) { if (getenv('DEBUG')) { $this->logger->debug($message, $extra); } return $this; }
/** * @param $queueId * @param $instance * @return Worker */ public function register($queueId, $instance) { /** @var EntityManager $em */ $em = $this->doctrine->getManager(); $host = gethostname(); $pid = getmypid(); /** @var Worker $worker */ $worker = $this->getWorker(['queue' => $queueId, 'instance' => $instance, 'host' => $host]); if ($worker == null) { $worker = new Worker(); $worker->setHost($host); $worker->setInstance($instance); $worker->setQueue($queueId); $worker->setStatus(Worker::STATUS_IDLE); $worker->setLastChangeDate(new \Datetime()); $worker->setPid($pid); } else { $worker->setStatus(Worker::STATUS_IDLE); $worker->setLastChangeDate(new \Datetime()); $worker->setPid($pid); } $em->persist($worker); $em->flush(); $this->logger->debug("Registered worker entity", $worker->__toArray()); return $worker; }
/** * @return void */ public function run() { $logger = new Logger('default'); $sagaFactory = new GenericSagaFactory(); $sagaStorage = new MemorySagaStorage(); $sagaRepository = new SagaRepository($sagaStorage, new JsonSerializer()); $resolver = new SimpleAssociationValueResolver(); $sagaManager = new SimpleSagaManager([ToDoSaga::class], $sagaRepository, $resolver, $sagaFactory); $eventBus = new SimpleEventBus([]); $eventBus->setLogger(new EventLogger($logger)); $eventBus->addHandler(Event::class, $sagaManager); $eventStore = new EventStore($eventBus, new MemoryEventStorage(), new JsonSerializer(), new EventClassMap([ToDoItemCreated::class, ToDoItemDone::class, DeadlineExpired::class])); $factory = new GenericAggregateFactory(ToDoItem::class); $repository = new EventSourcingRepository($factory, $eventStore); $commandHandler = new ToDoCommandHandler($repository); $commandBus = new SimpleCommandBus([CreateToDoItem::class => $commandHandler, MarkItemDone::class => $commandHandler]); $loggingCommandInterceptor = new LoggingInterceptor(new CommandLogger($logger)); $commandGateway = new DefaultCommandGateway($commandBus, [$loggingCommandInterceptor]); $toCompleteId = Identity::createNew(); $commandGateway->send(new CreateToDoItem($toCompleteId, "Item to complete", PHP_INT_MAX)); $sagaIds = $sagaRepository->find(ToDoSaga::class, new AssociationValue('identity', $toCompleteId->getValue())); $logger->debug("Active sagas found:", ['count' => count($sagaIds), 'saga' => !empty($sagaIds) ? $sagaStorage->findById($sagaIds[0]->getValue()) : '']); $commandGateway->send(new MarkItemDone($toCompleteId)); $sagaIds = $sagaRepository->find(ToDoSaga::class, new AssociationValue('identity', $toCompleteId->getValue())); $logger->debug("Active sagas found:", ['count' => count($sagaIds), 'saga' => !empty($sagaIds) ? $sagaStorage->findById($sagaIds[0]->getValue())['serialized'] : '']); }
/** * @param $dependency_manager * @param $token * @return Updater */ public function create($dependency_manager, $full_name, $token) { $this->logger->debug(__METHOD__); switch ($dependency_manager) { case 'composer': $manager = new ComposerDependencyManager(); break; case 'npm': $manager = new NpmDependencyManager(); break; default: throw new Exception("{$dependency_manager} is not supported"); // throw exception } $client = new Client(); $this->logger->debug(sprintf("Client::setEnterpriseUrl() %s", $this->git_hub_host)); if (!empty($this->git_hub_host)) { // seems there's a bug here? //$client->setEnterpriseUrl($this->git_hub_host); } $git_hub_repo = new GitHubRepository($client, $full_name, $token, $this->logger); $git_hub_repo->authenticate(); $temp_dir = $this->repository_dir . '/' . rand(); $file_system = new FileSystem($temp_dir); $file_system->makeDirectory(); return new Updater($git_hub_repo, $manager, $file_system, $this->logger); }
public function preExecute(Request $request) { $this->componentName = $this->container->getParameter('app_name'); $this->initLogger(); $this->initTemp(); $pathInfo = explode('/', $request->getPathInfo()); $this->logger->debug('Component ' . $this->componentName . ' started action ' . (count($pathInfo) > 2 ? $pathInfo[2] : "")); }
public function send($mobile, $message) { $data = $this->buildSendData($mobile, $message); $this->sendResult = $this->doSend($data); if ($this->logger) { $this->logger->debug('发送短信', ['mobile' => $mobile, 'message' => $message, 'result' => $this->sendResult, 'method' => __METHOD__]); } }
protected function processMessage(QueueMessage $message) { $msg = null; if (isset($message->getBody()->Message)) { $msg = json_decode($message->getBody()->Message); } $this->logger->debug("Processing kill message", ['message' => $msg]); if ($msg != null) { $jobId = $msg->jobId; /** @var Job $job */ $job = $this->elasticsearch->getJob($jobId); if (!is_null($job)) { if ($job->getProcess()['host'] == gethostname()) { if ($job->getStatus() == Job::STATUS_WAITING) { $job->setStatus(Job::STATUS_CANCELLED); $job->setResult(['message' => 'Job cancelled by user']); $this->getComponentJobMapper($job->getComponent())->update($job); $this->logger->info("receive-kill: Job '{$jobId}' cancelled", ['job' => $job->getData()]); $this->requeue($job->getId()); } else { if ($job->getStatus() == Job::STATUS_PROCESSING) { $job->setStatus(Job::STATUS_TERMINATING); $this->getComponentJobMapper($job->getComponent())->update($job); $pid = $job->getProcess()['pid']; // kill child processes $process = new Process(' function getcpid() { cpids=`pgrep -P $1|xargs` for cpid in $cpids; do echo "$cpid" getcpid $cpid done } getcpid ' . $pid); $process->run(); $processes = $process->getOutput(); if ($processes && count(explode("\n", $processes))) { foreach (explode("\n", $processes) as $child) { if ($child != '') { (new Process("sudo kill -KILL {$child}"))->run(); } } } // kill parent process posix_kill($pid, SIGKILL); $this->logger->info("receive-kill: Job '{$jobId}' killed", ['job' => $job->getData()]); } else { $this->logger->info("receive-kill: Job is not in waiting or processing state", ['job' => $job->getData()]); } } } } } else { $this->logger->warn("Corrupted message received", ['message' => $message]); } $this->queue->deleteMessage($message); }
public function testLogsLevelAndLevelName() { $this->logger->debug('debug message'); $this->logger->critical('critical message'); $sql = 'SELECT * FROM logs WHERE level_name = \'%s\''; $debugLog = $this->pdo->query(sprintf($sql, 'DEBUG'))->fetch(); $criticalLog = $this->pdo->query(sprintf($sql, 'CRITICAL'))->fetch(); $this->assertNotEmpty($debugLog); $this->assertNotEmpty($criticalLog); $this->assertEquals($debugLog['message'], 'debug message'); $this->assertEquals($criticalLog['message'], 'critical message'); }
/** * @param Logger $log * @param array $phpcs - ['encoding' => '....', 'standard' => '...'] */ public function __construct(Logger $log, array $config) { $this->log = $log; if (!empty($config['installed_paths'])) { $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = array('installed_paths' => str_replace('%root%', dirname(__DIR__), $config['installed_paths'])); $this->log->debug("installed_paths=" . $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA']['installed_paths']); } $this->phpcs = new \PHP_CodeSniffer($verbosity = 0, $tabWidth = 0, $config['encoding'], $interactive = false); $this->log->debug("PhpCs config", $config); $this->phpcs->cli->setCommandLineValues(['--report=json', '--standard=' . $config['standard']]); $this->phpcs->initStandard($config['standard']); }
/** * Gets a message from RabbitMQ, checks it's a valid transaction and saves it into DB. * * @param AMQPMessage $rawMessage */ public function process(AMQPMessage $rawMessage) { $this->logger->debug('Processing message ' . $rawMessage->body); try { $message = Transaction::extractFromJson($rawMessage->body); $message->checkSanity(); $this->messageDbModel->save($message); } catch (Exception $e) { // either transaction contains invalid data or there was an error in db $this->logger->warn($e->getMessage()); } }
/** * Вызывает соответствующий метод в конкретной реализации, * самостоятельно занимаясь кэшированием, логгированием * и измерением времени * * @param string $method Вызываемый метод * @param array $args Переданные в метод аргументы * * @return Response * @throws ConfigurationErrorException * @throws \InvalidArgumentException */ public function __call($method, array $args = []) { $cacheKey = md5(serialize(func_get_args())); $args = $this->createArgs($args); $timer = $this->pinba->start(['call' => sprintf('%s->%s', get_class($this), $method), 'args' => $args]); $this->logger->info(sprintf('%s->%s', get_class($this), $method), $args); $this->checkIsConfigured(); $item = $this->cacher->getItem($cacheKey); $inCache = !$item->isMiss(); $this->logger->info(sprintf('item found in cache: %s', $inCache ? 'yes' : 'no')); if ($inCache) { $this->logger->info('get from cache'); $response = $item->get(); } else { $this->logger->info('get from source'); $response = $this->implementation($method, $args); $expiresDefault = array_key_exists('default', $this->cacherExpires) ? $this->cacherExpires['default'] : 0; $expires = array_key_exists($method, $this->cacherExpires) ? $this->cacherExpires[$method] : $expiresDefault; $item->set($response, $expires); if (!$response->isOk()) { $this->logger->error('error response', [$response->getError()]); } else { $this->logger->debug('successful response', [$response->getContent()]); } } $this->pinba->stop($timer); $this->logger->info('pinba', $this->pinba->info($timer)); return $response; }
private function sendRequest($url, $method, $request) { try { if (strtoupper($method) == 'GET') { $this->logger->debug("Sending GET request to {$url}, query=" . json_encode($request)); $reply = $this->httpClient->get($url, ['query' => $request]); } else { $this->logger->debug("Sending {$method} request to {$url}, body=" . json_encode($request)); $reply = $this->httpClient->send($this->httpClient->createRequest($method, $url, ['body' => json_encode($request)])); } } catch (RequestException $e) { //Stash error: it can't send more then 1mb of json data. So just skip suck pull requests or files $this->logger->debug("Request finished with error: " . $e->getMessage()); if ($e->getMessage() == 'cURL error 56: Problem (3) in the Chunked-Encoded data') { throw new Exception\StashJsonFailure($e->getMessage(), $e->getRequest(), $e->getResponse(), $e); } else { throw $e; } } $this->logger->debug("Request finished"); $json = (string) $reply->getBody(); //an: пустой ответ - значит все хорошо if (empty($json)) { return true; } $data = json_decode($json, true); if ($data === null && $data != 'null') { $this->logger->addError("Invalid json received", ['url' => $url, 'method' => $method, 'request' => $request, 'reply' => $json]); throw new \Exception('invalid_json_received'); } return $data; }
public function debug($message, array $args = [], array $context = []) { if (count($args)) { $message = vsprintf($message, $args); } return parent::debug($message, $context); }
/** * @return void */ public function run() { $logger = new Logger('default'); $serializer = new JsonSerializer(); $stateStorage = new MemoryStateStorage(); $toDoItemProjections = new ToDoItemProjections($stateStorage); $eventStore = new EventStore(new SimpleEventBus([ToDoItemCreated::class => [$toDoItemProjections], ToDoItemDone::class => [$toDoItemProjections], DeadlineExpired::class => [$toDoItemProjections]]), new MemoryEventStorage(), $serializer, new EventClassMap([ToDoItemCreated::class, ToDoItemDone::class, DeadlineExpired::class])); $repository = new EventSourcingRepository(new GenericAggregateFactory(ToDoItem::class), $eventStore); $toDoItemCommandHandler = new ToDoCommandHandler($repository); $commandGateWay = new DefaultCommandGateway(new SimpleCommandBus([CreateToDoItem::class => $toDoItemCommandHandler, MarkItemDone::class => $toDoItemCommandHandler]), [new LoggingInterceptor(new CommandLogger($logger))]); $toDoId = Identity::createNew(); $commandGateWay->send(new CreateToDoItem($toDoId, "Wash the dishes", 5)); $logger->debug("Current state of ToDoItem", ['item' => $serializer->serialize($stateStorage->find($toDoId->getValue()))]); $commandGateWay->send(new MarkItemDone($toDoId)); $logger->debug("Current state of ToDoItem", ['item' => $serializer->serialize($stateStorage->find($toDoId->getValue()))]); }
/** * Handle PHP error * Takes input from PHPs built in error handler logs it * throws a jazzee exception to handle if the error reporting level is high enough * @param $code * @param $message * @param $file * @param $line * @throws \Jazzee\Exception */ public function handleError($code, $message, $file, $line) { /* Map the PHP error to a Log priority. */ switch ($code) { case E_WARNING: case E_USER_WARNING: $priority = \Monolog\Logger::WARNING; break; case E_NOTICE: case E_USER_NOTICE: $priority = \Monolog\Logger::INFO; break; case E_ERROR: case E_USER_ERROR: $priority = \Monolog\Logger::ERROR; break; default: $priority = \Monolog\Logger::INFO; } // Error reporting is currently turned off or suppressed with @ if (error_reporting() === 0) { $this->_log->debug('Supressed error: ' . $message . ' in ' . $file . ' at line ' . $line); return false; } $this->_log->addRecord($priority, $message . ' in ' . $file . ' at line ' . $line); throw new \Exception('Jazzee caught a PHP error: ' . $message . ' in ' . $file . ' at line ' . $line); }
/** * Send poll request from task response * * If response is not from async task, return null * * @param Elasticsearch\Job $job * @param \GuzzleHttp\Psr7\Response $response * @param Encryptor $encryptor * @param int $retriesCount * @return \GuzzleHttp\Psr7\Response|null */ public function sendOrchestratorPollRequest(Elasticsearch\Job $job, \GuzzleHttp\Psr7\Response $response, Encryptor $encryptor, $retriesCount) { if ($response->getStatusCode() != 202) { return null; } try { $data = ResponseDecoder::decode($response); if (!is_array($data)) { throw new \Exception('Not json reponse'); } if (empty($data['url'])) { return null; } } catch (\Exception $e) { //@TODO log error with debug priority return null; } $timeout = 2; try { return $this->get($data['url'], array('config' => array('curl' => array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0)), 'headers' => array('X-StorageApi-Token' => $encryptor->decrypt($job->getToken()), 'X-KBC-RunId' => $job->getRunId(), 'X-User-Agent', KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . " - JobExecutor", 'X-Orchestrator-Poll', (int) $retriesCount), 'timeout' => 60 * $timeout)); } catch (RequestException $e) { $handlerContext = $e->getHandlerContext(); if (is_array($handlerContext)) { if (array_key_exists('errno', $handlerContext)) { if ($handlerContext['errno'] == CURLE_OPERATION_TIMEOUTED) { $this->logger->debug('curl.debug', array('handlerContext' => $e->getHandlerContext())); throw new Exception\CurlException(sprintf('Task polling timeout after %d minutes', $timeout), $e->getRequest(), $e->getResponse(), $e); } } } throw $e; } }
private function isParallelLimitExceeded() { // skip validation for components without limit if (in_array($this->job->getComponent(), Limits::unlimitedComponents())) { $this->logger->debug('isParallelLimitExceeded - NO - unlimited component'); return false; } $maxLimit = Limits::getParallelLimit($this->storageApiService->getTokenData()); /** @var Search $elasticSearch */ $elasticSearch = $this->getContainer()->get('syrup.elasticsearch.search'); $jobs = $elasticSearch->getJobs(array('projectId' => $this->job->getProject()['id'], 'query' => sprintf('(%s) AND (%s)', sprintf('status:%s OR status:%s', Job::STATUS_PROCESSING, Job::STATUS_TERMINATING), implode(' AND ', array_map(function ($name) { return '-component:' . $name; }, Limits::unlimitedComponents()))))); if (count($jobs) < $maxLimit) { $this->logger->debug('isParallelLimitExceeded - NO - free workers ' . ($maxLimit - count($jobs))); return false; } $this->logger->debug('isParallelLimitExceeded - full workers ' . ($maxLimit - count($jobs))); if ($this->job->getNestingLevel() >= 1) { $runIds = explode('.', $this->job->getRunId()); unset($runIds[count($runIds) - 1]); $jobs = $elasticSearch->getJobs(array('projectId' => $this->job->getProject()['id'], 'query' => sprintf('(%s) AND (%s) AND (%s) AND (%s)', sprintf('status:%s OR status:%s', Job::STATUS_PROCESSING, Job::STATUS_TERMINATING), implode(' AND ', array_map(function ($name) { return '-component:' . $name; }, Limits::unlimitedComponents())), sprintf('runId:%s.*', implode('.', $runIds)), sprintf('nestingLevel:%s', $this->job->getNestingLevel())))); if (!count($jobs)) { $this->logger->debug('isParallelLimitExceeded - NO - free at nesting level'); return false; } } $this->logger->debug('isParallelLimitExceeded - YES - any free worker'); return true; }
/** * Command start time (without microseconds) * @return \DateTime */ protected function getStartTime() { $date = \DateTime::createFromFormat('U', (int) ($this->stopWatchEvent->getOrigin() / 1000)); if (!$date) { $this->logger->debug('getStartTime error', array('tag' => 'UNABLE_TO_CREATE_DATETIME', 'origin' => $this->stopWatchEvent->getOrigin(), 'originType' => gettype($this->stopWatchEvent->getOrigin()))); } return $date; }
public function testChangeChannel() { $redis = \Mockery::mock('Predis\\Client')->shouldReceive('publish')->times(1)->with('different', \Mockery::any())->mock(); $monolog = new Logger('test'); $redisPublisher = new RedisPublisher($redis); $monolog->pushHandler(new PublishHandler($redisPublisher)); $redisPublisher->setChannel('different'); $monolog->debug('the message was: {message}', ['DEBUG!']); }
/** * Handles anything we need to do when we are shutting down */ public function __destruct() { $up_time = date_diff(new \DateTime(date(DATE_ISO8601, $this->stop_time)), new \DateTime(date(DATE_ISO8601, $this->start_time))); $memory_usage = !function_exists('memory_get_usage') ? '0' : round(memory_get_usage() / 1024 / 1024, 2) . 'MB'; $message = sprintf('uptime: %s, memory usage: %s', $up_time->format('%h hours, %i minutes, %s seconds'), $memory_usage); if (isset($this->logger)) { $this->logger->debug($message); } }
public function work(\GearmanWorker $worker) { $worker->addOptions(GEARMAN_WORKER_NON_BLOCKING); $getWorkAttempts = 0; do { $workRes = $worker->work(); $getWorkAttempts++; $this->logger->debug("Get work attempt res: " . serialize($workRes)); $this->logger->debug("Attempts number: " . serialize($getWorkAttempts)); sleep(1); if ($workRes) { $this->taskWasGot = true; } } while ($workRes === false && $getWorkAttempts < WorkersConstants::MAX_GET_TASK_ATTEMPTS); if ($worker->returnCode() != GEARMAN_SUCCESS) { $this->logger->error("Not correct Gearman worker execution:" . $worker->returnCode()); } return null; }
/** * @param string $templateName * @param array $vars * @param string[] $headers * @return Response */ protected function render($templateName, $vars = null, $headers = null) { if ($this->requiresLogin && !$this->isLoggedIn()) { new Response("permission denied", Response::HTTP_FORBIDDEN, array("contentType" => "text/plain")); } $startTime = microtime(true); $content = $this->renderer->loadTemplate($templateName)->render($vars ?: $this->getDefaultVars()); $this->logger->debug(sprintf("%s: render response in %.3fs", get_class($this), microtime(true) - $startTime)); return new Response($content, Response::HTTP_OK, $headers ?: $this->getDefaultHeaders()); }
/** * Syncs the database of unified entities with the entities of each social * channel configured to be looked up by the aggregator * * @return void */ public function syncDatabase() { foreach ($this->harvestedServices as $service) { // we use duck typing here instead of interfaces. // we try to keep the social media services independend // of the AggregatorBundle /* if (!method_exists($service, 'syncDatabase')) { throw new AggregatorException('The service of class '.get_class($service). ' does not have a syncDatabase method and is therefor not usable by '. 'the aggregator. Correct your services.yml'); } */ if (!method_exists($service, 'getFeed')) { throw new AggregatorException('The service of class ' . get_class($service) . ' does not have a getFeed method and is therefor not usable by ' . 'the aggregator. Correct your services.yml'); } $this->logger->debug('Syncing ' . get_class($service)); // sync database // $service->syncDatabase(); - must be made manually this only syncs from table to table // fetch the newly synced entities, the target is to sync our unified repo $feed = $service->getFeed(false); // sync the unified social entity repository with the corresponding services $repository = $this->em->getRepository($this->unifiedSocialEntityClass); foreach ($feed as $socialEntity) { // yeah, type switching, again because we dont want a // dependency on the AggregatorBundle $unified = null; if ($socialEntity instanceof TwitterEntityInterface && !count($repository->findOneBy(array('type' => get_class($socialEntity), 'foreignKey' => $socialEntity->getId())))) { $unified = new $this->unifiedSocialEntityClass(); $unified->setApproved($this->autoApprove); $unified->setType(get_class($socialEntity)); $this->converterService->mapTwitterEntity($socialEntity, $unified); } elseif ($socialEntity instanceof InstagramEntityInterface && !count($repository->findOneBy(array('type' => get_class($socialEntity), 'foreignKey' => $socialEntity->getId())))) { $unified = new $this->unifiedSocialEntityClass(); $unified->setApproved($this->autoApprove); $unified->setType(get_class($socialEntity)); $this->converterService->mapInstagramEntity($socialEntity, $unified); } elseif ($socialEntity instanceof FacebookEntityInterface && !count($repository->findOneBy(array('type' => get_class($socialEntity), 'foreignKey' => $socialEntity->getId())))) { $unified = new $this->unifiedSocialEntityClass(); $unified->setApproved($this->autoApprove); $unified->setType(get_class($socialEntity)); $this->converterService->mapFacebookEntity($socialEntity, $unified); } elseif ($socialEntity instanceof YoutubeEntityInterface && !count($repository->findOneBy(array('type' => get_class($socialEntity), 'foreignKey' => $socialEntity->getId())))) { $unified = new $this->unifiedSocialEntityClass(); $unified->setApproved($this->autoApprove); $unified->setType(get_class($socialEntity)); $this->converterService->mapYoutubeEntity($socialEntity, $unified); } if ($unified != null) { $this->em->persist($unified); } } $this->em->flush(); } }
public function stop() { if (!$this->getPid()) { throw new \Exception("Process not running"); } foreach (range(1, 10) as $i) { switch ($i) { case 1: $this->logger->debug('Sending SIGTERM'); posix_kill($this->getPid(), SIGTERM); if (posix_get_last_error() == SOCKET_EPERM) { throw new \Exception("You do not have permission to stop this process"); } if ($this->status() != self::RUNNING_OK) { $this->logger->debug('First attempt results in full stop!'); break 2; } break; case 10: $this->logger->debug('Sending SIGKILL!!'); posix_kill($this->getPid(), SIGKILL); if ($this->status() != self::RUNNING_OK) { $this->logger->debug('Results in full stop!'); break 2; } break; default: $this->logger->debug('Sending another SIGTERM'); posix_kill($this->getPid(), SIGTERM); if ($this->status() != self::RUNNING_OK) { $this->logger->debug('Results in full stop!'); break 2; } break; } sleep(3); } if ($this->status() == self::RUNNING_OK) { throw new \Exception("There was an error attempting to end the process"); } $this->clearPid(); }
/** * @param $msg */ public function __invoke(array $msg) { list($zmqId, $delim, $hmac, $header, $parentHeader, $metadata, $content) = $msg; $header = json_decode($header, true); $content = json_decode($content, true); $this->logger->debug('Received message', ['processId' => getmypid(), 'zmqId' => $zmqId, 'delim' => $delim, 'hmac' => $hmac, 'header' => $header, 'parentHeader' => $parentHeader, 'metadata' => $metadata, 'content' => $content]); if ('kernel_info_request' === $header['msg_type']) { $this->kernelInfoAction->call($header, $content); } elseif ('execute_request' === $header['msg_type']) { $this->executeAction->call($header, $content); } elseif ('history_request' === $header['msg_type']) { $this->historyAction->call($header, $content); } elseif ('shutdown_request' === $header['msg_type']) { $this->shutdownAction->call($header, $content); } elseif ('comm_open' === $header['msg_type']) { // TODO: Research about what should be done. } else { $this->logger->error('Unknown message type', ['processId' => getmypid(), 'header' => $header]); } }
protected function execute(InputInterface $input, OutputInterface $output) { $logger = new Logger(new StreamHandler('php://output')); $channel = $this->getContainer()->get('dz.slack.channels')->getId($input->getArgument('channel')); if (empty($channel)) { $logger->error('channel "' . $channel . '" does not exists'); return; } $lastTimestamp = time(); while (true) { try { $latestMessages = $this->getContainer()->get('dz.slack.channels')->history($channel, $lastTimestamp); foreach ($latestMessages as $message) { if ($message->isBot() === true) { continue; } $logger->debug('Handling Message of Type : "' . $message->getType() . '"'); $event = Event::MESSAGE; switch ($message->getType()) { case Message::TYPE_MESSAGE: $event = Event::MESSAGE; break; case Message::TYPE_CHANNEL_JOIN: $event = Event::JOIN; break; case Message::TYPE_CHANNEL_LEAVE: $event = Event::LEAVE; break; } $logger->debug('Dispatching "' . $event . '"'); $this->getContainer()->get('event_dispatcher')->dispatch($event, new Events\MessageEvent($channel, $message)); $lastTimestamp = $message->getId(); } $logger->debug('Handled ' . count($latestMessages) . ' Messages'); } catch (\Exception $e) { $logger->error($e->getMessage()); $logger->error($e->getTraceAsString()); } sleep(self::PROCESS_ITERATION_SLEEP); } }
public function delete() { $body = $this->buildRequestBody(new Highlight(false)); try { $result = $this->client->deleteByQuery($body); } catch (\Exception $e) { if ($this->debug) { $this->logger->debug($this->translator->get('query_error') . json_encode($body)); } $result = null; } return $result; }
/** * @return Logger */ protected function getJobLogger() { $jobLogger = new Logger('Jobs'); $lineFormatter = new LineFormatter("[%datetime%] %message% %context% %extra%\n", null, true, true); $streamHandler = new StreamHandler("php://output"); $streamHandler->setFormatter($lineFormatter); $jobLogger->pushHandler($streamHandler); $fileHandler = new RotatingFileHandler(storage_path() . '/logs/jobs.log'); $fileHandler->setFormatter($lineFormatter); $jobLogger->pushHandler($fileHandler); $jobLogger->debug(static::class); return $jobLogger; }
public function onKernelException(GetResponseForExceptionEvent $event) { /** @var OrchestratorException $exception */ $exception = $event->getException(); $exceptionId = KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . '-' . md5(microtime()); if (!$exception instanceof OrchestratorException) { return; } $event->stopPropagation(); $data = array(); $data["status"] = $exception->getType(); $data["message"] = $exception->getMessage(); // getMessage $data["code"] = $exception->getExceptionCode(); // getExceptionCode $response = new JsonResponse($data); $response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Content-Type', 'application/json'); $response->setStatusCode($exception->getStatusCode() ? $exception->getStatusCode() : 400); $this->logger->debug($exception->getMessage(), array('exception' => $exception, 'exceptionId' => $exceptionId)); $event->setResponse($response); }
/** * */ public function remove(TopicInterface $topic, $andFlush = true) { $category = $topic->getCategory(); $this->logger->debug(sprintf('Removing all posts associated with topic: %s.', $topic->getId())); $posts = $this->TopicManager->findAllByTopic($topic); $this->TopicManager->removeAll($posts); $this->logger->debug(sprintf('Removing topic: %s.', $topic->getId())); $this->objectManager->remove($topic); if ($andFlush) { $this->objectManager->flush(); //$this->categoryUpdater->update($category); } }