public function run($data) { if (array_key_exists('search', $data) && !empty($data['search'])) { $search = $data['search']; $this->Twitter = ConnectionManager::getDataSource('twitter'); switch ($search) { default: $this->getSearchResults($search); $nextUpdate = '+30 Minutes'; break; case '*global*': $this->getGlobal($search); $nextUpdate = '+5 Minutes'; break; } //check if there is already a task for this term. $findConf = array('conditions' => array('fetched' => null, 'data LIKE' => '%' . $search . '%')); $alreadyPresent = $this->QueuedTask->find('count', $findConf); if ($alreadyPresent == false) { if ($this->QueuedTask->createJob('twitterscrape', array('search' => $search), $nextUpdate)) { $this->out('Searchterm update Queued'); } else { $this->err('Could not create Twitterscrape Job.'); } } else { $this->err('There seems to be another job queued for this term, job not requeued.'); } return true; } else { $this->out('No Search term found, Cancelling'); // return true so the task does NOT get requeued. return true; } }