Пример #1
0
 /**
  * @param GuzzleClient $client
  * @param RequestInterface $request
  * @return ResponseInterface
  */
 public function handle(GuzzleClient $client, RequestInterface $request)
 {
     try {
         $response = $client->send(new HttpRequest($request->getMethod(), $request->getUri(), $request->getHeaders(), $this->jsonEncoder->encode($request->getBody())));
     } catch (\Exception $e) {
         $this->logger->debug(sprintf('Exception thrown during Guzzle request'), ['message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile(), 'trace' => $e->getTraceAsString()]);
         $response = new Response(500);
         if ($e instanceof ClientException) {
             $response = new Response(401);
         }
     }
     return $request->getResponseFactory()->create($response);
 }
Пример #2
0
 /**
  * append a new Job
  * @param JobQueue\Job $job
  */
 public function appendJob(JobInterface $job)
 {
     $jobID = rand(0, 10000000000000);
     while (count($this->currentJobs) >= $this->maxProcesses) {
         $this->logger->debug("Maximum children allowed, waiting...");
         sleep(1);
     }
     $pid = pcntl_fork();
     if ($pid == -1) {
         //Problem launching the job
         $this->logger->critical('Could not launch new job, exiting');
         return false;
     } else {
         if ($pid) {
             // Parent process
             // Sometimes you can receive a signal to the childSignalHandler function before this code executes if
             // the child script executes quickly enough!
             //
             $this->currentJobs[$pid] = $jobID;
             // In the event that a signal for this pid was caught before we get here, it will be in our signalQueue array
             // So let's go ahead and process it now as if we'd just received the signal
             if (isset($this->signalQueue[$pid])) {
                 $this->logger->debug("found {$pid} in the signal queue, processing it now");
                 $this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
                 unset($this->signalQueue[$pid]);
             }
         } else {
             //Forked child, do your deeds....
             $exitStatus = 0;
             //Error code if you need to or whatever
             $job->setPid(getmypid());
             $job->run();
             exit($exitStatus);
         }
     }
     return true;
 }