コード例 #1
0
ファイル: TestWorker.php プロジェクト: mailru/queue-processor
 public function process(Task $task)
 {
     Logger::getLogger('queue')->info("begin id:{$task->getId()} (data:{$this->testField})");
     usleep(mt_rand(200000, 500000));
     // todo remove from queue, or unlock
     Logger::getLogger('queue')->info("end id:{$task->getId()} (data:{$this->testField})");
 }
コード例 #2
0
ファイル: LoggerTest.php プロジェクト: mitallast/php-logger
 public function testTest()
 {
     Logger::configure(['appenders' => ['stream' => ['class' => AppenderStream::class, 'stream' => '/dev/null']], 'root' => ['appenders' => ['stream']]]);
     $logger = Logger::getLogger('test');
     $start = microtime(1);
     for ($i = 1000; --$i;) {
         $logger->info('test');
     }
     $end = microtime(1);
     $this->assertLessThan(1.0, $end - $start, 'logger > root > stream');
     $logger = Logger::getRootLogger();
     $start = microtime(1);
     for ($i = 1000; --$i;) {
         $logger->info('test');
     }
     $end = microtime(1);
     $this->assertLessThan(1.0, $end - $start, 'root > stream');
     $appenders = Logger::getRootLogger()->getAppenders();
     $appender = $appenders[0];
     $start = microtime(1);
     for ($i = 1000; --$i;) {
         $appender->append($logger, Logger::INFO, 'test', null);
     }
     $end = microtime(1);
     $this->assertLessThan(1.0, $end - $start, 'stream');
 }
コード例 #3
0
ファイル: FileQueue.php プロジェクト: mailru/queue-processor
 public function unlockTasks(array $tasks = null)
 {
     $logger = Logger::getLogger('file-queue');
     $logger->info('unlock tasks');
     if ($tasks === null) {
         $tasks = $this->tasks;
     }
     $statusFileObject = $this->getStatusFileObject();
     if (!$statusFileObject->flock(LOCK_EX)) {
         throw new \RuntimeException("Can't get lock for status file {$this->getStatusFile()}");
     }
     $tasksFileObject = new \SplFileObject($this->getTasksFile(), 'a');
     foreach ($tasks as $task) {
         if ($tasksFileObject->fputcsv([$task->getId(), $task->getData()]) === false) {
             throw new \RuntimeException("Can't write task to tasks file {$this->getTasksFile()}");
         }
     }
     if (!$statusFileObject->flock(LOCK_UN)) {
         $logger->warn("Can't release lock");
     }
 }
コード例 #4
0
ファイル: Processor.php プロジェクト: mailru/queue-processor
 private function fork()
 {
     for ($i = 0; $i < 3; ++$i) {
         if (isset($pid)) {
             usleep(1000000);
         }
         $pid = pcntl_fork();
         if ($pid >= 0) {
             return $pid;
         }
         $error_number = pcntl_get_last_error();
         $error = "[{$error_number}] " . pcntl_strerror($error_number);
         Logger::getLogger('queue')->warn("Can`t fork, retryNumber={$i}, pid: '" . var_export($pid, true) . "', error: '{$error}'", new Exception());
     }
     throw new RuntimeException('Can`t fork');
 }
コード例 #5
0
 protected function getMougrimLogger($category)
 {
     return MougrimLogger::getLogger($category);
 }
コード例 #6
0
 /**
  * Использовать при SIGTERM.
  */
 public function signalTerminate()
 {
     Logger::getLogger('queue')->info('worker is begin terminate');
     // используется флаг, который проверяется только в процессоре и ворцером игнорируется
     $this->terminate = true;
 }