Example #1
0
 public function testFits()
 {
     $this->assertTrue(Table::fits('wow', Table::TYPE_VARCHAR));
     $this->assertTrue(Table::fits($this->getLongString(25600), Table::TYPE_LONGTEXT));
     $this->assertFalse(Table::fits('wow', Table::TYPE_VARCHAR, 2));
     $this->assertFalse(Table::fits($this->getLongString(25600), Table::TYPE_TEXT));
 }
Example #2
0
 /**
  * Build a job.
  *
  * @param string $task
  * @param string $data
  * @param int $retries
  *
  * @return Job
  */
 public function make($task, $data = '{}', $retries = 0)
 {
     $job = new Job();
     $job->state = JobState::IDLE;
     $job->task = $task;
     $job->retries = $retries;
     // Use a safe default if nothing or an empty string.
     if (empty($data)) {
         $data = '{}';
     }
     // Try to serialize to JSON if its an object.
     if (is_object($data) || is_array($data)) {
         $data = json_encode($data);
     }
     // Check if the input is valid JSON.
     if (!$this->isJson($data)) {
         throw new InvalidArgumentException('Data is not valid JSON.');
     }
     // Check if the data will fit inside a job record.
     if (!Table::fits($data, Table::TYPE_TEXT)) {
         throw new InvalidArgumentException('Data is too large for a job.');
     }
     $job->data = $data;
     return $job;
 }
Example #3
0
 /**
  * Append a line to this jobs' message.
  *
  * @param string $message
  *
  * @return Job
  */
 public function append($message)
 {
     $newMessage = $this->message . $message . "\n";
     if (Table::fits($newMessage, Table::TYPE_TEXT)) {
         $this->message = $newMessage;
     } else {
         $this->message = mb_strcut(mb_strlen($message), 0) . $message . "\n";
     }
     $this->save();
 }