/** * Clear a queue. * * Remove all jobs inside a queue. If more than one queue is present, it will prompt * the user which queue to clear via a menu. * * If the queues are empty, they are removed from the queues list. * * @since 3.3.0 * @return bool False is clearing the queues fails. */ public function clear() { $this->out('<info>' . __d('cake_resque', 'Clearing queues') . '</info>'); // List of all queues $queues = array_unique(CakeResque::getQueues()); if (empty($queues)) { $this->out(__d('cake_resque', 'There is no queues to clear')); return false; } $queueIndex = []; if (isset($this->args[0])) { if (in_array($this->args[0], $queues)) { $queueIndex[] = array_search($this->args[0], $queues) + 1; } } else { if (!$this->params['all'] && count($queues) > 1) { $this->out(__d('cake_resque', 'Queues list') . ':'); $i = 1; foreach ($queues as $queue) { $this->out(sprintf(" [%3d] - %-'.20s<bold>%'.9s</bold> jobs", $i++, $queue, number_format(CakeResque::getQueueSize($queue)))); } $options = range(1, $i - 1); if ($i > 2) { $this->out(' [all] - ' . __d('cake_resque', 'Clear all queues')); $options[] = 'all'; } $in = $this->in(__d('cake_resque', 'Queue to clear') . ': ', $options); if ($in == 'all') { $queueIndex = range(1, count($queues)); } else { $queueIndex[] = $in; } } else { $queueIndex = range(1, count($queues)); } } foreach ($queueIndex as $index) { $queue = $queues[$index - 1]; $this->out(__d('cake_resque', 'Clearing {0} ... ', $queue), 0); $cleared = CakeResque::clearQueue($queue); if ($cleared) { CakeResque::removeQueue($queue); $this->out('<success>' . __d('cake_resque', 'Done') . '</success>'); } else { $this->out('<error>' . __d('cake_resque', 'Fail') . '</error>'); } } return true; }
<?php /** * CakeResque bootstrap file. * * Used to load CakeResque class and initialize it. * * PHP version 5 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @author Wan Qi Chen <*****@*****.**> * @copyright Copyright 2012, Wan Qi Chen <*****@*****.**> * @link http://cakeresque.kamisama.me * @package CakeResque * @subpackage CakeResque.Config * @since 0.5 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ use CakeResque\CakeResque; CakeResque::init();