DominionEnterprises\Mongo\Queue::ackSend PHP Method

ackSend() public method

Atomically acknowledge and send a message to the queue.
public ackSend ( array $message, array $payload, integer $earliestGet, float $priority, boolean $newTimestamp = true ) : void
$message array the message to ack received from get()
$payload array the data to store in the message to send. Data is handled same way as \MongoDB\Collection::insertOne()
$earliestGet integer earliest unix timestamp the message can be retreived.
$priority float priority for order out of get(). 0 is higher priority than 1
$newTimestamp boolean true to give the payload a new timestamp or false to use given message timestamp
return void
    public function ackSend(array $message, array $payload, $earliestGet = 0, $priority = 0.0, $newTimestamp = true)
    {
        $id = null;
        if (array_key_exists('id', $message)) {
            $id = $message['id'];
        }
        if (!is_a($id, 'MongoDB\\BSON\\ObjectID')) {
            throw new \InvalidArgumentException('$message does not have a field "id" that is a ObjectID');
        }
        if (!is_int($earliestGet)) {
            throw new \InvalidArgumentException('$earliestGet was not an int');
        }
        if (!is_float($priority)) {
            throw new \InvalidArgumentException('$priority was not a float');
        }
        if (is_nan($priority)) {
            throw new \InvalidArgumentException('$priority was NaN');
        }
        if ($newTimestamp !== true && $newTimestamp !== false) {
            throw new \InvalidArgumentException('$newTimestamp was not a bool');
        }
        //Ensure $earliestGet is between 0 and MONGO_INT32_MAX
        $earliestGet = min(max(0, $earliestGet * 1000), self::MONGO_INT32_MAX);
        $toSet = ['payload' => $payload, 'running' => false, 'resetTimestamp' => new \MongoDB\BSON\UTCDateTime(self::MONGO_INT32_MAX), 'earliestGet' => new \MongoDB\BSON\UTCDateTime($earliestGet), 'priority' => $priority];
        if ($newTimestamp) {
            $toSet['created'] = new \MongoDB\BSON\UTCDateTime((int) (microtime(true) * 1000));
        }
        //using upsert because if no documents found then the doc was removed (SHOULD ONLY HAPPEN BY SOMEONE MANUALLY)
        //so we can just send
        $this->collection->updateOne(['_id' => $id], ['$set' => $toSet], ['upsert' => true]);
    }