@@ -6,66 +6,66 @@ |
||
| 6 | 6 | class Config |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * |
|
| 11 | - * @return int |
|
| 12 | - */ |
|
| 13 | - public static function defaultWorkerTimeout() |
|
| 14 | - { |
|
| 15 | - return Configure::read('Queue.defaultWorkerTimeout', 600); // 10min |
|
| 16 | - } |
|
| 9 | + /** |
|
| 10 | + * |
|
| 11 | + * @return int |
|
| 12 | + */ |
|
| 13 | + public static function defaultWorkerTimeout() |
|
| 14 | + { |
|
| 15 | + return Configure::read('Queue.defaultWorkerTimeout', 600); // 10min |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * |
|
| 20 | - * @return int |
|
| 21 | - */ |
|
| 22 | - public static function workerMaxRuntime() |
|
| 23 | - { |
|
| 24 | - return Configure::read('Queue.workerMaxRuntime', 120); |
|
| 25 | - } |
|
| 18 | + /** |
|
| 19 | + * |
|
| 20 | + * @return int |
|
| 21 | + */ |
|
| 22 | + public static function workerMaxRuntime() |
|
| 23 | + { |
|
| 24 | + return Configure::read('Queue.workerMaxRuntime', 120); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @return int |
|
| 30 | - */ |
|
| 31 | - public static function cleanupTimeout() |
|
| 32 | - { |
|
| 33 | - return Configure::read('Queue.cleanupTimeout', 2592000); // 30 days |
|
| 34 | - } |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @return int |
|
| 30 | + */ |
|
| 31 | + public static function cleanupTimeout() |
|
| 32 | + { |
|
| 33 | + return Configure::read('Queue.cleanupTimeout', 2592000); // 30 days |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * |
|
| 38 | - * @return int |
|
| 39 | - */ |
|
| 40 | - public static function sleepTime() |
|
| 41 | - { |
|
| 42 | - return Configure::read('Queue.sleepTime', 10); |
|
| 43 | - } |
|
| 36 | + /** |
|
| 37 | + * |
|
| 38 | + * @return int |
|
| 39 | + */ |
|
| 40 | + public static function sleepTime() |
|
| 41 | + { |
|
| 42 | + return Configure::read('Queue.sleepTime', 10); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * |
|
| 47 | - * @return int |
|
| 48 | - */ |
|
| 49 | - public static function gcprob() |
|
| 50 | - { |
|
| 51 | - return Configure::read('Queue.gcprob', 10); |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * |
|
| 47 | + * @return int |
|
| 48 | + */ |
|
| 49 | + public static function gcprob() |
|
| 50 | + { |
|
| 51 | + return Configure::read('Queue.gcprob', 10); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * |
|
| 56 | - * @return int |
|
| 57 | - */ |
|
| 58 | - public static function defaultWorkerRetries() |
|
| 59 | - { |
|
| 60 | - return Configure::read('Queue.defaultWorkerRetries', 1); |
|
| 61 | - } |
|
| 54 | + /** |
|
| 55 | + * |
|
| 56 | + * @return int |
|
| 57 | + */ |
|
| 58 | + public static function defaultWorkerRetries() |
|
| 59 | + { |
|
| 60 | + return Configure::read('Queue.defaultWorkerRetries', 1); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * |
|
| 65 | - * @return int |
|
| 66 | - */ |
|
| 67 | - public static function maxWorkers() |
|
| 68 | - { |
|
| 69 | - return Configure::read('Queue.maxWorkers', 1); |
|
| 70 | - } |
|
| 63 | + /** |
|
| 64 | + * |
|
| 65 | + * @return int |
|
| 66 | + */ |
|
| 67 | + public static function maxWorkers() |
|
| 68 | + { |
|
| 69 | + return Configure::read('Queue.maxWorkers', 1); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | interface AddInterface |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Allows adding a task to the queue. |
|
| 15 | - * |
|
| 16 | - * Will create one example task in the queue, which later will be executed using run(). |
|
| 17 | - * |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - public function add(): void; |
|
| 13 | + /** |
|
| 14 | + * Allows adding a task to the queue. |
|
| 15 | + * |
|
| 16 | + * Will create one example task in the queue, which later will be executed using run(). |
|
| 17 | + * |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + public function add(): void; |
|
| 21 | 21 | } |
@@ -20,21 +20,21 @@ |
||
| 20 | 20 | class QueuedTask extends Entity |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $_accessible = [ |
|
| 30 | - 'task' => true, |
|
| 31 | - 'data' => true, |
|
| 32 | - 'not_before' => true, |
|
| 33 | - 'fetched' => true, |
|
| 34 | - 'completed' => true, |
|
| 35 | - 'failed_count' => true, |
|
| 36 | - 'failure_message' => true, |
|
| 37 | - 'worker_key' => true, |
|
| 38 | - 'created' => true |
|
| 39 | - ]; |
|
| 23 | + /** |
|
| 24 | + * |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $_accessible = [ |
|
| 30 | + 'task' => true, |
|
| 31 | + 'data' => true, |
|
| 32 | + 'not_before' => true, |
|
| 33 | + 'fetched' => true, |
|
| 34 | + 'completed' => true, |
|
| 35 | + 'failed_count' => true, |
|
| 36 | + 'failure_message' => true, |
|
| 37 | + 'worker_key' => true, |
|
| 38 | + 'created' => true |
|
| 39 | + ]; |
|
| 40 | 40 | } |
@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'Queue' => [ |
|
| 5 | - // time (in seconds) after which a job is requeued if the worker doesn't report back |
|
| 6 | - 'defaultWorkerTimeout' => 1800, |
|
| 4 | + 'Queue' => [ |
|
| 5 | + // time (in seconds) after which a job is requeued if the worker doesn't report back |
|
| 6 | + 'defaultWorkerTimeout' => 1800, |
|
| 7 | 7 | |
| 8 | - // seconds of running time after which the worker will terminate (0 = unlimited) |
|
| 9 | - 'workerMaxRuntime' => 120, |
|
| 8 | + // seconds of running time after which the worker will terminate (0 = unlimited) |
|
| 9 | + 'workerMaxRuntime' => 120, |
|
| 10 | 10 | |
| 11 | - // minimum time (in seconds) which a task remains in the database before being cleaned up. |
|
| 12 | - 'cleanupTimeout' => 2592000, // 30 days |
|
| 11 | + // minimum time (in seconds) which a task remains in the database before being cleaned up. |
|
| 12 | + 'cleanupTimeout' => 2592000, // 30 days |
|
| 13 | 13 | |
| 14 | - /* Optional */ |
|
| 14 | + /* Optional */ |
|
| 15 | 15 | |
| 16 | - 'isSearchEnabled' => true, |
|
| 17 | - ], |
|
| 16 | + 'isSearchEnabled' => true, |
|
| 17 | + ], |
|
| 18 | 18 | ]; |
@@ -8,80 +8,80 @@ |
||
| 8 | 8 | class TaskFinder |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * |
|
| 13 | - * @var array|null |
|
| 14 | - */ |
|
| 15 | - protected $tasks; |
|
| 11 | + /** |
|
| 12 | + * |
|
| 13 | + * @var array|null |
|
| 14 | + */ |
|
| 15 | + protected $tasks; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Returns all possible Queue tasks. |
|
| 19 | - * |
|
| 20 | - * Makes sure that app tasks are prioritized over plugin ones. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function allAppAndPluginTasks() |
|
| 25 | - { |
|
| 26 | - if ($this->tasks !== null) { |
|
| 27 | - return $this->tasks; |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * Returns all possible Queue tasks. |
|
| 19 | + * |
|
| 20 | + * Makes sure that app tasks are prioritized over plugin ones. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function allAppAndPluginTasks() |
|
| 25 | + { |
|
| 26 | + if ($this->tasks !== null) { |
|
| 27 | + return $this->tasks; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $paths = App::path('Shell/Task'); |
|
| 31 | - $this->tasks = []; |
|
| 30 | + $paths = App::path('Shell/Task'); |
|
| 31 | + $this->tasks = []; |
|
| 32 | 32 | |
| 33 | - foreach ($paths as $path) { |
|
| 34 | - $Folder = new Folder($path); |
|
| 35 | - $this->tasks = $this->getAppPaths($Folder); |
|
| 36 | - } |
|
| 37 | - $plugins = Plugin::loaded(); |
|
| 38 | - foreach ($plugins as $plugin) { |
|
| 39 | - $pluginPaths = App::path('Shell/Task', $plugin); |
|
| 40 | - foreach ($pluginPaths as $pluginPath) { |
|
| 41 | - $Folder = new Folder($pluginPath); |
|
| 42 | - $pluginTasks = $this->getPluginPaths($Folder, $plugin); |
|
| 43 | - $this->tasks = array_merge($this->tasks, $pluginTasks); |
|
| 44 | - } |
|
| 45 | - } |
|
| 33 | + foreach ($paths as $path) { |
|
| 34 | + $Folder = new Folder($path); |
|
| 35 | + $this->tasks = $this->getAppPaths($Folder); |
|
| 36 | + } |
|
| 37 | + $plugins = Plugin::loaded(); |
|
| 38 | + foreach ($plugins as $plugin) { |
|
| 39 | + $pluginPaths = App::path('Shell/Task', $plugin); |
|
| 40 | + foreach ($pluginPaths as $pluginPath) { |
|
| 41 | + $Folder = new Folder($pluginPath); |
|
| 42 | + $pluginTasks = $this->getPluginPaths($Folder, $plugin); |
|
| 43 | + $this->tasks = array_merge($this->tasks, $pluginTasks); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $this->tasks; |
|
| 48 | - } |
|
| 47 | + return $this->tasks; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * |
|
| 52 | - * @param \Cake\Filesystem\Folder $Folder The directory |
|
| 53 | - * |
|
| 54 | - * @return array |
|
| 55 | - */ |
|
| 56 | - protected function getAppPaths(Folder $Folder) |
|
| 57 | - { |
|
| 58 | - $res = array_merge($this->tasks, $Folder->find('Queue.+\.php')); |
|
| 59 | - foreach ($res as &$r) { |
|
| 60 | - $r = basename($r, 'Task.php'); |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * |
|
| 52 | + * @param \Cake\Filesystem\Folder $Folder The directory |
|
| 53 | + * |
|
| 54 | + * @return array |
|
| 55 | + */ |
|
| 56 | + protected function getAppPaths(Folder $Folder) |
|
| 57 | + { |
|
| 58 | + $res = array_merge($this->tasks, $Folder->find('Queue.+\.php')); |
|
| 59 | + foreach ($res as &$r) { |
|
| 60 | + $r = basename($r, 'Task.php'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $res; |
|
| 64 | - } |
|
| 63 | + return $res; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * @param \Cake\Filesystem\Folder $Folder The directory |
|
| 69 | - * @param string $plugin The plugin name |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - protected function getPluginPaths(Folder $Folder, $plugin) |
|
| 74 | - { |
|
| 75 | - $res = $Folder->find('Queue.+Task\.php'); |
|
| 76 | - foreach ($res as $key => $r) { |
|
| 77 | - $name = basename($r, 'Task.php'); |
|
| 78 | - if (in_array($name, $this->tasks)) { |
|
| 79 | - unset($res[$key]); |
|
| 80 | - continue; |
|
| 81 | - } |
|
| 82 | - $res[$key] = $plugin . '.' . $name; |
|
| 83 | - } |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * @param \Cake\Filesystem\Folder $Folder The directory |
|
| 69 | + * @param string $plugin The plugin name |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + protected function getPluginPaths(Folder $Folder, $plugin) |
|
| 74 | + { |
|
| 75 | + $res = $Folder->find('Queue.+Task\.php'); |
|
| 76 | + foreach ($res as $key => $r) { |
|
| 77 | + $name = basename($r, 'Task.php'); |
|
| 78 | + if (in_array($name, $this->tasks)) { |
|
| 79 | + unset($res[$key]); |
|
| 80 | + continue; |
|
| 81 | + } |
|
| 82 | + $res[$key] = $plugin . '.' . $name; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return $res; |
|
| 86 | - } |
|
| 85 | + return $res; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -18,57 +18,57 @@ |
||
| 18 | 18 | abstract class QueueTask extends Shell implements QueueTaskInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - public $queueModelClass = 'Queue.QueuedTasks'; |
|
| 21 | + /** |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + public $queueModelClass = 'Queue.QueuedTasks'; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @var \Queue\Model\Table\QueuedTasksTable |
|
| 30 | - */ |
|
| 31 | - public $QueuedTasks; |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @var \Queue\Model\Table\QueuedTasksTable |
|
| 30 | + */ |
|
| 31 | + public $QueuedTasks; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Timeout for run, after which the Task is reassigned to a new worker. |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - public $timeout = 120; |
|
| 33 | + /** |
|
| 34 | + * Timeout for run, after which the Task is reassigned to a new worker. |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + public $timeout = 120; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Number of times a failed instance of this task should be restarted before giving up. |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - public $retries = 1; |
|
| 40 | + /** |
|
| 41 | + * Number of times a failed instance of this task should be restarted before giving up. |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + public $retries = 1; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * @param \Cake\Console\ConsoleIo|null $io IO |
|
| 50 | - */ |
|
| 51 | - public function __construct(ConsoleIo $io = null) |
|
| 52 | - { |
|
| 53 | - parent::__construct($io); |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * @param \Cake\Console\ConsoleIo|null $io IO |
|
| 50 | + */ |
|
| 51 | + public function __construct(ConsoleIo $io = null) |
|
| 52 | + { |
|
| 53 | + parent::__construct($io); |
|
| 54 | 54 | |
| 55 | - $this->loadModel($this->queueModelClass); |
|
| 56 | - } |
|
| 55 | + $this->loadModel($this->queueModelClass); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - * @throws \InvalidArgumentException |
|
| 62 | - */ |
|
| 63 | - protected function queueTaskName() |
|
| 64 | - { |
|
| 65 | - $class = get_class($this); |
|
| 58 | + /** |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + * @throws \InvalidArgumentException |
|
| 62 | + */ |
|
| 63 | + protected function queueTaskName() |
|
| 64 | + { |
|
| 65 | + $class = get_class($this); |
|
| 66 | 66 | |
| 67 | - preg_match('#\\\\Queue(.+)Task$#', $class, $matches); |
|
| 68 | - if (!$matches) { |
|
| 69 | - throw new InvalidArgumentException('Invalid class name: ' . $class); |
|
| 70 | - } |
|
| 67 | + preg_match('#\\\\Queue(.+)Task$#', $class, $matches); |
|
| 68 | + if (!$matches) { |
|
| 69 | + throw new InvalidArgumentException('Invalid class name: ' . $class); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $matches[1]; |
|
| 73 | - } |
|
| 72 | + return $matches[1]; |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -7,82 +7,82 @@ |
||
| 7 | 7 | class QueueExampleTask extends QueueTask implements AddInterface |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Timeout for run, after which the task is reassigned to a new worker. |
|
| 12 | - * |
|
| 13 | - * @var int |
|
| 14 | - */ |
|
| 15 | - public $timeout = 10; |
|
| 10 | + /** |
|
| 11 | + * Timeout for run, after which the task is reassigned to a new worker. |
|
| 12 | + * |
|
| 13 | + * @var int |
|
| 14 | + */ |
|
| 15 | + public $timeout = 10; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Timeout for cleanup, after which completed jobs are deleted (in seconds). |
|
| 19 | - * |
|
| 20 | - * @var int |
|
| 21 | - */ |
|
| 22 | - public $cleanupTimeout = 600; |
|
| 17 | + /** |
|
| 18 | + * Timeout for cleanup, after which completed jobs are deleted (in seconds). |
|
| 19 | + * |
|
| 20 | + * @var int |
|
| 21 | + */ |
|
| 22 | + public $cleanupTimeout = 600; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Number of times a failed instance of this task should be restarted before giving up. |
|
| 26 | - * |
|
| 27 | - * @var int |
|
| 28 | - */ |
|
| 29 | - public $retries = 0; |
|
| 24 | + /** |
|
| 25 | + * Number of times a failed instance of this task should be restarted before giving up. |
|
| 26 | + * |
|
| 27 | + * @var int |
|
| 28 | + */ |
|
| 29 | + public $retries = 0; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Stores any failure messages triggered during run(). |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public $failureMessage = ''; |
|
| 31 | + /** |
|
| 32 | + * Stores any failure messages triggered during run(). |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public $failureMessage = ''; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Example add functionality. |
|
| 40 | - * Will create one example job in the queue, which later will be executed using run(); |
|
| 41 | - * |
|
| 42 | - * To invoke from CLI execute: |
|
| 43 | - * - bin/cake queue add Example |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function add(): void |
|
| 48 | - { |
|
| 49 | - $this->out(__d('queue', 'CakePHP Queue Example task.')); |
|
| 50 | - $this->hr(); |
|
| 51 | - $this->out(__d('queue', 'This is a very simple example of a queueTask.')); |
|
| 52 | - $this->out(__d('queue', 'Now adding an example Task Job into the Queue.')); |
|
| 53 | - $this->out(__d('queue', 'This task will only produce some console output on the worker that it runs on.')); |
|
| 54 | - $this->out(' '); |
|
| 55 | - $this->out(__d('queue', 'To run a Worker use:')); |
|
| 56 | - $this->out(__d('queue', ' cake queue runworker')); |
|
| 57 | - $this->out(' '); |
|
| 58 | - $this->out(__d('queue', 'You can find the sourcecode of this task in: ')); |
|
| 59 | - $this->out(__FILE__); |
|
| 60 | - $this->out(' '); |
|
| 38 | + /** |
|
| 39 | + * Example add functionality. |
|
| 40 | + * Will create one example job in the queue, which later will be executed using run(); |
|
| 41 | + * |
|
| 42 | + * To invoke from CLI execute: |
|
| 43 | + * - bin/cake queue add Example |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function add(): void |
|
| 48 | + { |
|
| 49 | + $this->out(__d('queue', 'CakePHP Queue Example task.')); |
|
| 50 | + $this->hr(); |
|
| 51 | + $this->out(__d('queue', 'This is a very simple example of a queueTask.')); |
|
| 52 | + $this->out(__d('queue', 'Now adding an example Task Job into the Queue.')); |
|
| 53 | + $this->out(__d('queue', 'This task will only produce some console output on the worker that it runs on.')); |
|
| 54 | + $this->out(' '); |
|
| 55 | + $this->out(__d('queue', 'To run a Worker use:')); |
|
| 56 | + $this->out(__d('queue', ' cake queue runworker')); |
|
| 57 | + $this->out(' '); |
|
| 58 | + $this->out(__d('queue', 'You can find the sourcecode of this task in: ')); |
|
| 59 | + $this->out(__FILE__); |
|
| 60 | + $this->out(' '); |
|
| 61 | 61 | |
| 62 | - // Adding a task of type 'example' with no additionally passed data |
|
| 63 | - if ($this->QueuedTasks->createJob('Example')) { |
|
| 64 | - $this->out(__d('queue', 'OK, job created, now run the worker')); |
|
| 65 | - } else { |
|
| 66 | - $this->err(__d('queue', 'Could not create Job')); |
|
| 67 | - } |
|
| 68 | - } |
|
| 62 | + // Adding a task of type 'example' with no additionally passed data |
|
| 63 | + if ($this->QueuedTasks->createJob('Example')) { |
|
| 64 | + $this->out(__d('queue', 'OK, job created, now run the worker')); |
|
| 65 | + } else { |
|
| 66 | + $this->err(__d('queue', 'Could not create Job')); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Example run function. |
|
| 72 | - * This function is executed, when a worker is executing a task. |
|
| 73 | - * The return parameter will determine, if the task will be marked completed, or be requeued. |
|
| 74 | - * |
|
| 75 | - * @param array $data The array passed to QueuedTasksTable::createJob() |
|
| 76 | - * @param int $taskId The id of the QueuedTask entity |
|
| 77 | - * @return void |
|
| 78 | - */ |
|
| 79 | - public function run(array $data, $taskId): void |
|
| 80 | - { |
|
| 81 | - $this->hr(); |
|
| 82 | - $this->out(__d('queue', 'CakePHP Queue Example task.')); |
|
| 83 | - $this->hr(); |
|
| 84 | - $this->out(__d('queue', ' ->Success, the Example Task was run.<-')); |
|
| 85 | - $this->out(' '); |
|
| 86 | - $this->out(' '); |
|
| 87 | - } |
|
| 70 | + /** |
|
| 71 | + * Example run function. |
|
| 72 | + * This function is executed, when a worker is executing a task. |
|
| 73 | + * The return parameter will determine, if the task will be marked completed, or be requeued. |
|
| 74 | + * |
|
| 75 | + * @param array $data The array passed to QueuedTasksTable::createJob() |
|
| 76 | + * @param int $taskId The id of the QueuedTask entity |
|
| 77 | + * @return void |
|
| 78 | + */ |
|
| 79 | + public function run(array $data, $taskId): void |
|
| 80 | + { |
|
| 81 | + $this->hr(); |
|
| 82 | + $this->out(__d('queue', 'CakePHP Queue Example task.')); |
|
| 83 | + $this->hr(); |
|
| 84 | + $this->out(__d('queue', ' ->Success, the Example Task was run.<-')); |
|
| 85 | + $this->out(' '); |
|
| 86 | + $this->out(' '); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -13,12 +13,12 @@ |
||
| 13 | 13 | interface QueueTaskInterface |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Main execution of the task. |
|
| 18 | - * |
|
| 19 | - * @param array $data The array passed to QueuedTasksTable::createJob() |
|
| 20 | - * @param int $taskId The id of the QueuedTask entity |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public function run(array $data, $taskId): void; |
|
| 16 | + /** |
|
| 17 | + * Main execution of the task. |
|
| 18 | + * |
|
| 19 | + * @param array $data The array passed to QueuedTasksTable::createJob() |
|
| 20 | + * @param int $taskId The id of the QueuedTask entity |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public function run(array $data, $taskId): void; |
|
| 24 | 24 | } |
@@ -2,14 +2,14 @@ discard block |
||
| 2 | 2 | use Cake\Datasource\ConnectionManager; |
| 3 | 3 | |
| 4 | 4 | if (!defined('DS')) { |
| 5 | - define('DS', DIRECTORY_SEPARATOR); |
|
| 5 | + define('DS', DIRECTORY_SEPARATOR); |
|
| 6 | 6 | } |
| 7 | 7 | if (!defined('WINDOWS')) { |
| 8 | - if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') { |
|
| 9 | - define('WINDOWS', true); |
|
| 10 | - } else { |
|
| 11 | - define('WINDOWS', false); |
|
| 12 | - } |
|
| 8 | + if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') { |
|
| 9 | + define('WINDOWS', true); |
|
| 10 | + } else { |
|
| 11 | + define('WINDOWS', false); |
|
| 12 | + } |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | define('ROOT', dirname(__DIR__)); |
@@ -32,25 +32,25 @@ discard block |
||
| 32 | 32 | require CORE_PATH . 'config/bootstrap.php'; |
| 33 | 33 | |
| 34 | 34 | Cake\Core\Configure::write('App', [ |
| 35 | - 'namespace' => 'App', |
|
| 36 | - 'encoding' => 'UTF-8', |
|
| 37 | - 'paths' => [ |
|
| 38 | - 'templates' => [ROOT . DS . 'tests' . DS . 'test_app' . DS . 'src' . DS . 'Template' . DS], |
|
| 39 | - ] |
|
| 35 | + 'namespace' => 'App', |
|
| 36 | + 'encoding' => 'UTF-8', |
|
| 37 | + 'paths' => [ |
|
| 38 | + 'templates' => [ROOT . DS . 'tests' . DS . 'test_app' . DS . 'src' . DS . 'Template' . DS], |
|
| 39 | + ] |
|
| 40 | 40 | ]); |
| 41 | 41 | |
| 42 | 42 | Cake\Core\Configure::write('debug', true); |
| 43 | 43 | |
| 44 | 44 | Cake\Core\Configure::write('EmailTransport', [ |
| 45 | - 'default' => [ |
|
| 46 | - 'className' => 'Debug', |
|
| 47 | - ], |
|
| 45 | + 'default' => [ |
|
| 46 | + 'className' => 'Debug', |
|
| 47 | + ], |
|
| 48 | 48 | ]); |
| 49 | 49 | Cake\Core\Configure::write('Email', [ |
| 50 | - 'default' => [ |
|
| 51 | - 'transport' => 'default', |
|
| 52 | - 'from' => 'you@localhost', |
|
| 53 | - ], |
|
| 50 | + 'default' => [ |
|
| 51 | + 'transport' => 'default', |
|
| 52 | + 'from' => 'you@localhost', |
|
| 53 | + ], |
|
| 54 | 54 | ]); |
| 55 | 55 | |
| 56 | 56 | mb_internal_encoding('UTF-8'); |
@@ -61,24 +61,24 @@ discard block |
||
| 61 | 61 | $Tmp->create(TMP . 'cache/views', 0770); |
| 62 | 62 | |
| 63 | 63 | $cache = [ |
| 64 | - 'default' => [ |
|
| 65 | - 'engine' => 'File', |
|
| 66 | - 'path' => CACHE, |
|
| 67 | - ], |
|
| 68 | - '_cake_core_' => [ |
|
| 69 | - 'className' => 'File', |
|
| 70 | - 'prefix' => 'crud_myapp_cake_core_', |
|
| 71 | - 'path' => CACHE . 'persistent/', |
|
| 72 | - 'serialize' => true, |
|
| 73 | - 'duration' => '+10 seconds', |
|
| 74 | - ], |
|
| 75 | - '_cake_model_' => [ |
|
| 76 | - 'className' => 'File', |
|
| 77 | - 'prefix' => 'crud_my_app_cake_model_', |
|
| 78 | - 'path' => CACHE . 'models/', |
|
| 79 | - 'serialize' => 'File', |
|
| 80 | - 'duration' => '+10 seconds', |
|
| 81 | - ], |
|
| 64 | + 'default' => [ |
|
| 65 | + 'engine' => 'File', |
|
| 66 | + 'path' => CACHE, |
|
| 67 | + ], |
|
| 68 | + '_cake_core_' => [ |
|
| 69 | + 'className' => 'File', |
|
| 70 | + 'prefix' => 'crud_myapp_cake_core_', |
|
| 71 | + 'path' => CACHE . 'persistent/', |
|
| 72 | + 'serialize' => true, |
|
| 73 | + 'duration' => '+10 seconds', |
|
| 74 | + ], |
|
| 75 | + '_cake_model_' => [ |
|
| 76 | + 'className' => 'File', |
|
| 77 | + 'prefix' => 'crud_my_app_cake_model_', |
|
| 78 | + 'path' => CACHE . 'models/', |
|
| 79 | + 'serialize' => 'File', |
|
| 80 | + 'duration' => '+10 seconds', |
|
| 81 | + ], |
|
| 82 | 82 | ]; |
| 83 | 83 | |
| 84 | 84 | Cake\Cache\Cache::setConfig($cache); |
@@ -86,37 +86,37 @@ discard block |
||
| 86 | 86 | Cake\Core\Plugin::getCollection()->add(new \Queue\Plugin()); |
| 87 | 87 | |
| 88 | 88 | Cake\Mailer\TransportFactory::setConfig('default', [ |
| 89 | - 'className' => 'Debug', |
|
| 89 | + 'className' => 'Debug', |
|
| 90 | 90 | ]); |
| 91 | 91 | Cake\Mailer\TransportFactory::setConfig('queue', [ |
| 92 | - 'className' => 'Queue.Queue', |
|
| 92 | + 'className' => 'Queue.Queue', |
|
| 93 | 93 | ]); |
| 94 | 94 | Cake\Mailer\Email::setConfig('default', [ |
| 95 | - 'transport' => 'default', |
|
| 95 | + 'transport' => 'default', |
|
| 96 | 96 | ]); |
| 97 | 97 | |
| 98 | 98 | // Allow local overwrite |
| 99 | 99 | // E.g. in your console: export db_dsn="mysql://root:[email protected]/cake_test" |
| 100 | 100 | if (!getenv('db_class') && getenv('db_dsn')) { |
| 101 | - ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]); |
|
| 101 | + ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]); |
|
| 102 | 102 | |
| 103 | - return; |
|
| 103 | + return; |
|
| 104 | 104 | } |
| 105 | 105 | if (!getenv('db_class')) { |
| 106 | - putenv('db_class=Cake\Database\Driver\Sqlite'); |
|
| 107 | - putenv('db_dsn=sqlite::memory:'); |
|
| 106 | + putenv('db_class=Cake\Database\Driver\Sqlite'); |
|
| 107 | + putenv('db_dsn=sqlite::memory:'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Uses Travis config then (MySQL, Postgres, ...) |
| 111 | 111 | ConnectionManager::setConfig('test', [ |
| 112 | - 'className' => 'Cake\Database\Connection', |
|
| 113 | - 'driver' => getenv('db_class'), |
|
| 114 | - 'dsn' => getenv('db_dsn'), |
|
| 115 | - 'database' => getenv('db_database'), |
|
| 116 | - 'username' => getenv('db_username'), |
|
| 117 | - 'password' => getenv('db_password'), |
|
| 118 | - 'timezone' => 'UTC', |
|
| 119 | - 'quoteIdentifiers' => true, |
|
| 120 | - 'cacheMetadata' => true, |
|
| 112 | + 'className' => 'Cake\Database\Connection', |
|
| 113 | + 'driver' => getenv('db_class'), |
|
| 114 | + 'dsn' => getenv('db_dsn'), |
|
| 115 | + 'database' => getenv('db_database'), |
|
| 116 | + 'username' => getenv('db_username'), |
|
| 117 | + 'password' => getenv('db_password'), |
|
| 118 | + 'timezone' => 'UTC', |
|
| 119 | + 'quoteIdentifiers' => true, |
|
| 120 | + 'cacheMetadata' => true, |
|
| 121 | 121 | |
| 122 | 122 | ]); |