コード例 #1
0
 /**
  *
  */
 public function run()
 {
     echo "ImagickTaskRunner started\n";
     /** @noinspection PhpUndefinedMethodInspection */
     \ImagickDemo\Imagick\functions::load();
     \ImagickDemo\ImagickDraw\functions::load();
     \ImagickDemo\ImagickPixel\functions::load();
     \ImagickDemo\ImagickKernel\functions::load();
     \ImagickDemo\ImagickPixelIterator\functions::load();
     \ImagickDemo\Tutorial\functions::load();
     $maxRunTime = 60;
     // one minute
     $maxRunTime *= 60;
     // 1hour
     // Each image generated hurries up the restart by 50 seconds
     // for a max of 72 images generated per run
     $taskPseudoTime = 50;
     $endTime = time() + $maxRunTime;
     $count = 0;
     while (time() < $endTime) {
         $task = $this->taskQueue->waitToAssignTask();
         if (!$task) {
             echo ".";
             $count = $count + 1;
             if ($count % 20 == 0) {
                 echo "\n";
             }
             //Sleep for 1/10th of a second
             usleep(100000);
             continue;
         }
         echo "A task! " . "\n";
         $endTime -= $taskPseudoTime;
         try {
             $startTime = microtime(true);
             $this->execute($task);
             $time = microtime(true) - $startTime;
             $this->asyncStats->recordTime(self::EVENT_IMAGE_GENERATED, $time);
             echo "Task complete\n";
             $this->taskQueue->completeTask($task);
         } catch (\ImagickException $ie) {
             echo "ImagickException running the task: " . $ie->getMessage();
             $this->taskQueue->errorTask($task, get_class($ie) . ": " . $ie->getMessage());
         } catch (\Auryn\BadArgumentException $bae) {
             //Log failed job
             echo "BadArgumentException running the task: " . $bae->getMessage();
             $this->taskQueue->errorTask($task, get_class($bae) . ": " . $bae->getMessage());
         } catch (\Exception $e) {
             echo "Exception running the task: " . $e->getMessage();
             $this->taskQueue->errorTask($task, get_class($e) . ": " . $e->getMessage());
         }
     }
     echo "\nImagickTaskRunner exiting\n";
 }
コード例 #2
0
 /**
  *
  */
 public function actuallyRun()
 {
     echo "ImagickTaskRunner::actuallyRun\n";
     try {
         echo "Waiting for task " . "\n";
         $task = $this->taskQueue->waitToAssignTask();
     } catch (QueueException $qe) {
         echo "QueueException running the task: " . $qe->getMessage() . "\n";
         return;
     }
     if (!$task) {
         self::tickTock();
         usleep(100000);
         //Sleep for 1/10th of a second
         return;
     }
     echo "A task!\n";
     try {
         $startTime = microtime(true);
         $this->execute($task);
         $time = microtime(true) - $startTime;
         $this->asyncStats->recordTime(self::EVENT_IMAGE_GENERATED, $time);
         echo "Task complete\n";
         $this->taskQueue->completeTask($task);
     } catch (\ImagickException $ie) {
         echo "ImagickException running the task: " . $ie->getMessage();
         $this->taskQueue->errorTask($task, get_class($ie) . ": " . $ie->getMessage());
         //   var_dump($ie->getTrace());
     } catch (\Auryn\BadArgumentException $bae) {
         //Log failed job
         echo "BadArgumentException running the task: " . $bae->getMessage();
         $this->taskQueue->errorTask($task, get_class($bae) . ": " . $bae->getMessage());
     } catch (\Exception $e) {
         echo "Exception running the task: " . $e->getMessage();
         $this->taskQueue->errorTask($task, get_class($e) . ": " . $e->getMessage());
         //var_dump($e->getTrace());
     }
 }
コード例 #3
0
 /**
  *
  */
 public function run()
 {
     echo "ImagickTaskRunner started\n";
     \Imagick::setResourceLimit(\Imagick::RESOURCETYPE_TIME, 60);
     /** @noinspection PhpUndefinedMethodInspection */
     \ImagickDemo\Imagick\functions::load();
     \ImagickDemo\ImagickDraw\functions::load();
     \ImagickDemo\ImagickPixel\functions::load();
     \ImagickDemo\ImagickKernel\functions::load();
     \ImagickDemo\ImagickPixelIterator\functions::load();
     \ImagickDemo\Tutorial\functions::load();
     $resetTimeResourceLimit = false;
     if (false) {
         // ImageMagick has a 'non-optimal' way of measuring time passed
         // https://github.com/ImageMagick/ImageMagick/issues/113
         // Currently it does not appear possible to have both protection
         $maxRunTime = 60;
         // one minute
         $maxRunTime *= 60;
         // 1hour
         // Each image generated hurries up the restart by 50 seconds
         // for a max of 72 images generated per run
         $taskPseudoTime = 50;
         $resetTimeResourceLimit = true;
         // End rant
     } else {
         //Start remove this when time limit can be controlled better
         $maxRunTime = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_TIME);
         // one minute
         if ($maxRunTime <= 10) {
             $maxRunTime = 45;
         }
         // Each image generated hurries up the restart by 2 seconds
         // for a max of 30 images generated per run
         $taskPseudoTime = 2;
         //End remove this when time limit can be controlled better
     }
     $endTime = time() + $maxRunTime;
     $count = 0;
     while (time() < $endTime) {
         if ($resetTimeResourceLimit === true) {
             \Imagick::setResourceLimit(\Imagick::RESOURCETYPE_TIME, 45);
         }
         $task = $this->taskQueue->waitToAssignTask();
         if (!$task) {
             echo ".";
             $count = $count + 1;
             if ($count % 20 == 0) {
                 echo "\n";
             }
             //Sleep for 1/10th of a second
             usleep(100000);
             continue;
         }
         echo "A task! " . "\n";
         $endTime -= $taskPseudoTime;
         try {
             $startTime = microtime(true);
             $this->execute($task);
             $time = microtime(true) - $startTime;
             $this->asyncStats->recordTime(self::EVENT_IMAGE_GENERATED, $time);
             echo "Task complete\n";
             $this->taskQueue->completeTask($task);
         } catch (\ImagickException $ie) {
             echo "ImagickException running the task: " . $ie->getMessage();
             $this->taskQueue->errorTask($task, get_class($ie) . ": " . $ie->getMessage());
         } catch (\Auryn\BadArgumentException $bae) {
             //Log failed job
             echo "BadArgumentException running the task: " . $bae->getMessage();
             $this->taskQueue->errorTask($task, get_class($bae) . ": " . $bae->getMessage());
         } catch (\Exception $e) {
             echo "Exception running the task: " . $e->getMessage();
             $this->taskQueue->errorTask($task, get_class($e) . ": " . $e->getMessage());
         }
     }
     echo "\nImagickTaskRunner exiting\n";
 }