private function findJobsByState($tube, $state, $searchStr, $limit = 25)
{
$jobList = array();
$job = null;
$total = $this->interface->getTubeStats($tube);
$totalJobs = 0;
try {
switch ($state) {
case 'ready':
$job = $this->interface->_client->useTube($tube)->peekReady();
$totalJobs = $total[2]['value'];
break;
case 'delayed':
$job = $this->interface->_client->useTube($tube)->peekDelayed();
$totalJobs = $total[4]['value'];
break;
case 'buried':
$job = $this->interface->_client->useTube($tube)->peekBuried();
$totalJobs = $total[5]['value'];
break;
}
} catch (Exception $e) {
}
if ($job === null) {
return $jobList;
}
$jobList = array();
$lastId = $job->getId() + $totalJobs;
$added = 0;
for ($id = $job->getId(); $id < $lastId; $id++) {
try {
$job = $this->interface->_client->peek($id);
if (strpos($job->getData(), $searchStr) !== false) {
$jobList[$id] = $job;
$added++;
}
} catch (Pheanstalk_Exception_ServerException $e) {
}
if ($added >= $limit || microtime(true) - $this->actionTimeStart > $limit) {
break;
}
}
return $jobList;
}