public function pop($topic, $timeout = PHP_INT_MAX)
{
/**
* @var \ManaPHP\Message\Queue\Adapter\Db\Model $model
* @var \ManaPHP\Message\Queue\Adapter\Db\Model $modelInstance
*/
$modelInstance = new $this->_model();
$startTime = time();
do {
$model = $modelInstance::findFirst([['topic' => $topic, 'deleted' => 0], 'order' => 'priority ASC, id ASC']);
if ($model && $modelInstance::updateAll(['deleted' => 1], ['id' => $model->id, 'deleted = 0'])) {
return $model->body;
}
sleep(1);
} while (time() - $startTime < $timeout);
return false;
}