Updated config format.
This commit is contained in:
parent
974a381b5a
commit
ab198e9ef1
@ -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'
|
||||
]
|
||||
]
|
||||
);
|
@ -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';
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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.");
|
||||
|
||||
|
@ -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.");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user