Phalcon\Queue\Beanstalk\Extended::putInTube PHP Method

putInTube() public method

Puts a job on the queue using specified tube.
public putInTube ( string $tube, string $data, array $options = null ) : boolean | string
$tube string
$data string
$options array
return boolean | string job id or false
    public function putInTube($tube, $data, $options = null)
    {
        if (null === $options) {
            $options = [];
        }
        if (!array_key_exists('delay', $options)) {
            $options['delay'] = self::DEFAULT_DELAY;
        }
        if (!array_key_exists('priority', $options)) {
            $options['priority'] = self::DEFAULT_PRIORITY;
        }
        if (!array_key_exists('ttr', $options)) {
            $options['ttr'] = self::DEFAULT_TTR;
        }
        $this->choose($this->getTubeName($tube));
        return parent::put($data, $options);
    }

Usage Example

示例#1
1
 /**
  * @depends testShouldGetTubes
  */
 public function testShouldDoWork()
 {
     if (!class_exists('\\duncan3dc\\Helpers\\Fork')) {
         $this->markTestSkipped(sprintf('%s used as a dependency \\duncan3dc\\Helpers\\Fork. You can install it by using' . 'composer require "duncan3dc/fork-helper":"*"', get_class($this->client)));
     }
     $expected = ['test-tube-1' => '1', 'test-tube-2' => '2'];
     foreach ($expected as $tube => $value) {
         $this->client->addWorker($tube, function (Job $job) {
             // Store string "test-tube-%JOB_BODY%" in shared memory
             $memory = shmop_open($this->shmKey, 'c', 0644, $this->shmLimit);
             $output = trim(shmop_read($memory, 0, $this->shmLimit));
             $output .= sprintf("\ntest-tube-%s", $job->getBody());
             shmop_write($memory, $output, 0);
             shmop_close($memory);
             exit(1);
         });
         $this->client->putInTube($tube, $value);
     }
     $this->client->doWork();
     $memory = shmop_open($this->shmKey, 'a', 0, 0);
     $output = shmop_read($memory, 0, $this->shmLimit);
     $this->assertTrue(shmop_delete($memory));
     shmop_close($memory);
     $this->assertNotEmpty($output);
     // Compare number of items in expected list with lines in shared memory
     $this->assertEquals(count($expected), count(array_unique(explode("\n", trim($output)))));
 }
All Usage Examples Of Phalcon\Queue\Beanstalk\Extended::putInTube