From ab198e9ef1abd16eea31434950047340ffdd634a Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Thu, 13 Feb 2020 14:06:23 +0100 Subject: [PATCH] Updated config format. --- config.tasks.php | 22 +++++++++++++++++-- .../Async/Executors/ShellExecutor.php | 7 ++++-- src/FuzeWorks/Async/TaskStorage.php | 8 +++++++ .../Async/TaskStorage/ArrayTaskStorage.php | 10 ++++----- src/FuzeWorks/Async/Tasks.php | 4 ++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/config.tasks.php b/config.tasks.php index 7a00481..922e272 100644 --- a/config.tasks.php +++ b/config.tasks.php @@ -42,12 +42,30 @@ return array( 'type' => 'ArrayTaskStorage', // For ArrayTaskStorage, first parameter is the file location of the array storage - 'parameters' => [dirname(__FILE__) . DS . 'storage.php'] + 'parameters' => [ + 'filename' => dirname(__FILE__) . DS . 'storage.php' + ], + + // For RedisTaskStorage, parameters are connection properties + #'parameters' => [ + # // Type can be 'tcp' or 'unix' + # 'socket_type' => 'tcp', + # // If socket_type == 'unix', set the socket here + # 'socket' => null, + # // If socket_type == 'tcp', set the host here + # 'host' => 'localhost', + # + # 'password' => null, + # 'port' => 6379, + # 'timeout' => 0 + #] ], 'Executor' => [ 'type' => 'ShellExecutor', // For ShellExecutor, first parameter is the file location of the worker script - 'parameters' => [dirname(__FILE__) . DS . 'bin' . DS . 'worker'] + 'parameters' => [ + 'workerFile' => dirname(__FILE__) . DS . 'bin' . DS . 'worker' + ] ] ); \ No newline at end of file diff --git a/src/FuzeWorks/Async/Executors/ShellExecutor.php b/src/FuzeWorks/Async/Executors/ShellExecutor.php index 69e5c18..30c5556 100644 --- a/src/FuzeWorks/Async/Executors/ShellExecutor.php +++ b/src/FuzeWorks/Async/Executors/ShellExecutor.php @@ -51,11 +51,14 @@ class ShellExecutor implements Executor /** * ShellExecutor constructor. * - * @param string $workerFile The worker script that shall run individual tasks + * @param array $parameters * @throws TasksException */ - public function __construct(string $workerFile) + public function __construct(array $parameters) { + // Fetch workerFile + $workerFile = $parameters['workerFile']; + // First determine the PHP binary $this->binary = PHP_BINDIR . DS . 'php'; diff --git a/src/FuzeWorks/Async/TaskStorage.php b/src/FuzeWorks/Async/TaskStorage.php index 08f1f4d..6548240 100644 --- a/src/FuzeWorks/Async/TaskStorage.php +++ b/src/FuzeWorks/Async/TaskStorage.php @@ -39,6 +39,14 @@ namespace FuzeWorks\Async; interface TaskStorage { + /** + * TaskStorage constructor. + * + * @throws TasksException + * @param array $parameters from config file + */ + public function __construct(array $parameters); + /** * Add a task to the TaskStorage. * diff --git a/src/FuzeWorks/Async/TaskStorage/ArrayTaskStorage.php b/src/FuzeWorks/Async/TaskStorage/ArrayTaskStorage.php index cd3197b..bbc0269 100644 --- a/src/FuzeWorks/Async/TaskStorage/ArrayTaskStorage.php +++ b/src/FuzeWorks/Async/TaskStorage/ArrayTaskStorage.php @@ -60,13 +60,13 @@ class ArrayTaskStorage implements TaskStorage protected $tasks = []; /** - * ArrayTaskStorage constructor. - * - * @param string $fileName Name of the Storage file - * @throws TasksException + * @inheritDoc */ - public function __construct(string $fileName) + public function __construct(array $parameters) { + // Load the filename for this taskStorage + $fileName = $parameters['filename']; + if (!file_exists($fileName)) throw new TasksException("Could not construct ArrayTaskStorage. Storage file '$fileName' doesn't exist."); diff --git a/src/FuzeWorks/Async/Tasks.php b/src/FuzeWorks/Async/Tasks.php index 9a8cbe2..18df927 100644 --- a/src/FuzeWorks/Async/Tasks.php +++ b/src/FuzeWorks/Async/Tasks.php @@ -116,7 +116,7 @@ class Tasks implements iLibrary if (!class_exists($class, true)) throw new TasksException("Could not get TaskStorage. Type of '$class' not found."); - $object = new $class(...$parameters); + $object = new $class($parameters); if (!$object instanceof TaskStorage) throw new TasksException("Could not get TaskStorage. Type '$class' is not instanceof TaskStorage."); @@ -137,7 +137,7 @@ class Tasks implements iLibrary if (!class_exists($class, true)) throw new TasksException("Could not get Executor. Type of '$class' not found."); - $object = new $class(...$parameters); + $object = new $class($parameters); if (!$object instanceof Executor) throw new TasksException("Could not get Executor. Type '$class' is not instanceof Executor.");