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; } }
/** * Add functionality. * Will create one example job in the queue, which later will be executed using run(); * * @return void */ public function add() { $this->out('CakePHP Queue Execute task.'); $this->hr(); if (count($this->args) < 2) { $this->out('This will run an shell command on the Server.'); $this->out('The task is mainly intended to serve as a kind of buffer for programm calls from a cakephp application.'); $this->out(' '); $this->out('Call like this:'); $this->out(' cake queue add execute *command* *param1* *param2* ...'); $this->out(' '); } else { $data = ['command' => $this->args[1], 'params' => array_slice($this->args, 2)]; if ($this->QueuedTask->createJob('Execute', $data)) { $this->out('Job created'); } else { $this->err('Could not create Job'); } } }
/** * Example add functionality. * Will create one example job in the queue, which later will be executed using run(); * * @return void */ public function add() { $this->out('CakePHP Queue LongExample task.'); $this->hr(); $this->out('This is a very simple but long running example of a QueueTask.'); $this->out('I will now add the Job into the Queue.'); $this->out('This job will need at least 2 minutes to complete.'); $this->out(' '); $this->out('To run a Worker use:'); $this->out(' cake Queue.Queue runworker'); $this->out(' '); $this->out('You can find the sourcecode of this task in:'); $this->out(__FILE__); $this->out(' '); /* * Adding a task of type 'example' with no additionally passed data */ if ($this->QueuedTask->createJob('LongExample', 2 * MINUTE)) { $this->out('OK, job created, now run the worker'); } else { $this->err('Could not create Job'); } }
/** * Example add functionality. * Will create one example job in the queue, which later will be executed using run(); */ public function add() { $this->out('CakePHP Queue Example task.'); $this->hr(); $this->out('This is a very simple example of a queueTask.'); $this->out('I will now add an example Job into the Queue.'); $this->out('This job will only produce some console output on the worker that it runs on.'); $this->out(' '); $this->out('To run a Worker use:'); $this->out(' cake queue runworker'); $this->out(' '); $this->out('You can find the sourcecode of this task in: '); $this->out(__FILE__); $this->out(' '); /** * Adding a task of type 'example' with no additionally passed data */ if ($this->QueuedTask->createJob('example', null)) { $this->out('OK, job created, now run the worker'); } else { $this->err('Could not create Job'); } }