/**
  * Send message to beanstalkd server.
  *
  * @param SyncTask $task
  */
 protected function send($task)
 {
     $content = json_encode(['id' => $task->getId(), 'task' => 'ongr.task.' . $task->getName(), 'args' => [implode(' ', array_merge([$task->getCommand(), '-e', $this->getEnvironment($task)], $task->getArguments()))]]);
     if ($this->connection) {
         $this->connection->useTube($task->getExchange())->put($content);
     }
     $this->logger && $this->logger->info('beanstalkd publish', [$task->getName(), $task->getPublishingType(), $task->getHost()]);
 }
 /**
  * Send message to AMQP server.
  *
  * @param SyncTask $task
  */
 protected function send($task)
 {
     $channel = $this->connection->channel();
     if ($channel) {
         $channel->exchange_declare($task->getExchange(), $task->getPublishingType(), false, true, false);
         $content = json_encode(['id' => $task->getId(), 'task' => 'ongr.acme_task.' . $task->getName(), 'args' => [implode(' ', array_merge([$task->getCommand(), '-e', $this->getEnvironment($task)], $task->getArguments()))]]);
         $message = new AMQPMessage($content, ['content_type' => 'application/json']);
         $this->logger && $this->logger->info('amqp publish', [$task->getName(), $task->getPublishingType(), $task->getHost()]);
         $channel->basic_publish($message, $task->getExchange(), $task->getHost());
         $channel->close();
     }
 }
Ejemplo n.º 3
0
 /**
  * Method to test whether exception is being thrown when task name is not set.
  */
 public function testGetNameException()
 {
     $task = new SyncTask(SyncTask::SYNC_TASK_BROADCAST);
     $this->setExpectedException('InvalidArgumentException');
     $task->getName();
 }