Skip to content

Instantly share code, notes, and snippets.

@colinmollenhour
Created December 30, 2011 23:23
Show Gist options
  • Save colinmollenhour/1541999 to your computer and use it in GitHub Desktop.
Save colinmollenhour/1541999 to your computer and use it in GitHub Desktop.
Mongo job queue
public function getNextJob()
{
$result = $this->_getWriteAdapter()->command(array(
'findAndModify' => $this->_collectionName,
'query' => array(
'status' => Cm_Mongo_Model_Job::STATUS_READY,
'execute_at' => array('$lte' => new MongoDate),
),
'sort' => array(
'priority' => 1,
'execute_at' => 1,
),
'update' => array(
'$set' => array(
'status' => Cm_Mongo_Model_Job::STATUS_RUNNING,
'pid' => getmypid(),
),
),
'fields' => $this->getDefaultLoadFields(new Varien_Object),
'new' => true,
));
if( empty($result['ok'])) {
return FALSE;
}
$data = $result['value'];
$job = Mage::getModel('mongo/job');
$this->hydrate($job, $data, TRUE);
return $job;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment