Release of RC1 #7
|
@ -23,4 +23,5 @@ steps:
|
|||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
environment:
|
||||
SUPERVISOR: ParallelSuperVisor
|
||||
TASKSTORAGE: RedisTaskStorage
|
||||
TASKSTORAGE: RedisTaskStorage
|
||||
TASKSTORAGE_REDIS_HOST: cache
|
|
@ -164,6 +164,9 @@ class DummyTaskStorage implements TaskStorage
|
|||
*/
|
||||
public function writeTaskOutput(Task $task, string $output, string $errors, int $statusCode, int $attempt = 0): bool
|
||||
{
|
||||
// First check if the task exists
|
||||
$task = $this->getTaskById($task->getId());
|
||||
|
||||
if (isset($this->taskOutput[$task->getId()]['task'][$attempt]))
|
||||
throw new TasksException("Could not write task output. Output already written.");
|
||||
|
||||
|
@ -181,6 +184,9 @@ class DummyTaskStorage implements TaskStorage
|
|||
*/
|
||||
public function writePostOutput(Task $task, string $output, string $errors, int $statusCode, int $attempt = 0): bool
|
||||
{
|
||||
// First check if the task exists
|
||||
$task = $this->getTaskById($task->getId());
|
||||
|
||||
if (isset($this->taskOutput[$task->getId()]['post'][$attempt]))
|
||||
throw new TasksException("Could not write task post output. Output already written.");
|
||||
|
||||
|
|
|
@ -206,6 +206,9 @@ class RedisTaskStorage implements TaskStorage
|
|||
// First get the task ID
|
||||
$taskId = $task->getId();
|
||||
|
||||
// Check if the task exists
|
||||
$task = $this->getTaskById($taskId);
|
||||
|
||||
// Check if the key already exists
|
||||
if ($this->conn->exists($this->key_prefix . $taskId . '_output_' . $attempt))
|
||||
throw new TasksException("Could not write task output. Output already written.");
|
||||
|
@ -226,6 +229,9 @@ class RedisTaskStorage implements TaskStorage
|
|||
// First get the task ID
|
||||
$taskId = $task->getId();
|
||||
|
||||
// Check if the task exists
|
||||
$task = $this->getTaskById($taskId);
|
||||
|
||||
// Check if the key already exists
|
||||
if ($this->conn->exists($this->key_prefix . $taskId . '_post_' . $attempt))
|
||||
throw new TasksException("Could not write post output. Output already written.");
|
||||
|
@ -286,6 +292,8 @@ class RedisTaskStorage implements TaskStorage
|
|||
foreach ($this->readTasks() as $task)
|
||||
$this->deleteTask($task);
|
||||
|
||||
$this->refreshTasks();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -59,7 +59,6 @@ class Tasks implements iLibrary
|
|||
{
|
||||
/** @var Config $config */
|
||||
$config = Factory::getInstance('config');
|
||||
$config->addComponentPath(dirname(__FILE__, 4), Priority::LOW);
|
||||
$this->cfg = $config->getConfig('tasks');
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*/
|
||||
|
||||
use FuzeWorks\Async\Task;
|
||||
use FuzeWorks\Async\Tasks;
|
||||
use FuzeWorks\Async\TasksException;
|
||||
use FuzeWorks\Async\TaskStorage;
|
||||
use FuzeWorks\Async\TaskStorage\DummyTaskStorage;
|
||||
|
@ -50,12 +51,14 @@ class TaskStorageTest extends TestCase
|
|||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->taskStorage = new DummyTaskStorage([]);
|
||||
$tasks = new Tasks();
|
||||
$this->taskStorage = $tasks->getTaskStorage();
|
||||
$this->taskStorage->reset();
|
||||
}
|
||||
|
||||
public function testDummyTaskStorageClass()
|
||||
{
|
||||
$this->assertInstanceOf('FuzeWorks\Async\TaskStorage\DummyTaskStorage', $this->taskStorage);
|
||||
$this->assertInstanceOf('FuzeWorks\Async\TaskStorage', $this->taskStorage);
|
||||
}
|
||||
|
||||
/* ---------------------------------- Writing and reading tasks ----------------------- */
|
||||
|
@ -74,11 +77,15 @@ class TaskStorageTest extends TestCase
|
|||
// Write task to storage and test properties of readTasks
|
||||
$this->assertTrue($this->taskStorage->addTask($dummyTask));
|
||||
$output = $this->taskStorage->readTasks();
|
||||
$this->assertContains($dummyTask, $output);
|
||||
$this->assertCount(1, $output);
|
||||
|
||||
// Get first
|
||||
$task = $output[0];
|
||||
$this->assertEquals($dummyTask, $task);
|
||||
|
||||
// Test if the properties match
|
||||
$this->assertEquals('testAddTask', $output[0]->getId());
|
||||
$this->assertEquals('none', $output[0]->getHandlerClass());
|
||||
$this->assertEquals('testAddTask', $task->getId());
|
||||
$this->assertEquals('none', $task->getHandlerClass());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,11 +132,11 @@ class TaskStorageTest extends TestCase
|
|||
$this->assertEquals('testGetTaskById2', $retrievedTask2->getId());
|
||||
|
||||
// Test they are not the same
|
||||
$this->assertNotSame($retrievedTask1, $retrievedTask2);
|
||||
$this->assertNotEquals($retrievedTask1, $retrievedTask2);
|
||||
|
||||
// And test they are the initial dummy tasks
|
||||
$this->assertSame($dummyTask1, $retrievedTask1);
|
||||
$this->assertSame($dummyTask2, $retrievedTask2);
|
||||
$this->assertEquals($dummyTask1, $retrievedTask1);
|
||||
$this->assertEquals($dummyTask2, $retrievedTask2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +209,7 @@ class TaskStorageTest extends TestCase
|
|||
$this->assertTrue($this->taskStorage->addTask($dummyTask));
|
||||
|
||||
// Test that it exists
|
||||
$this->assertSame($dummyTask, $this->taskStorage->getTaskById('testDeleteTask'));
|
||||
$this->assertEquals($dummyTask, $this->taskStorage->getTaskById('testDeleteTask'));
|
||||
|
||||
// Then remove the task
|
||||
$this->assertTrue($this->taskStorage->deleteTask($dummyTask));
|
||||
|
@ -233,9 +240,10 @@ class TaskStorageTest extends TestCase
|
|||
public function testWriteAndReadTaskOutput()
|
||||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteTaskOutput', 'none');
|
||||
$dummyTask = new Task('testWriteAndReadTaskOutput', 'none');
|
||||
|
||||
// First write the task output
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
$this->assertTrue($this->taskStorage->writeTaskOutput($dummyTask, 'output', 'errors', 0, 0));
|
||||
|
||||
// Then try to read the output
|
||||
|
@ -245,6 +253,19 @@ class TaskStorageTest extends TestCase
|
|||
$this->assertEquals(0, $output['statusCode']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testWriteAndReadTaskOutput
|
||||
*/
|
||||
public function testWriteAndReadTaskOutputTaskNotExist()
|
||||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskOutputTaskNotExist', 'none');
|
||||
|
||||
// Write output while the task does not exist yet, expect exception
|
||||
$this->expectException(TasksException::class);
|
||||
$this->taskStorage->writeTaskOutput($dummyTask, 'output', 'errors', 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testWriteAndReadTaskOutput
|
||||
*/
|
||||
|
@ -252,6 +273,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskOutputAttempts', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
// Write the different outputs. Done in a weird order to make sure the default is inserted not first or last
|
||||
// to make sure the default is not selected by accident by the TaskStorage
|
||||
|
@ -291,6 +313,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskOutputAlreadyExists', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
// Write a first time
|
||||
$this->assertTrue($this->taskStorage->writeTaskOutput($dummyTask, 'output', 'errors', 100, 0));
|
||||
|
@ -307,6 +330,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskOutputNotExist', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
$this->assertNull($this->taskStorage->readTaskOutput($dummyTask));
|
||||
}
|
||||
|
@ -320,6 +344,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskPostOutput', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
// First write the task output
|
||||
$this->assertTrue($this->taskStorage->writePostOutput($dummyTask, 'postOutput', 'errors', 0, 0));
|
||||
|
@ -338,6 +363,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskPostOutputAttempts', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
// Write the different outputs. Done in a weird order to make sure the default is inserted not first or last
|
||||
// to make sure the default is not selected by accident by the TaskStorage
|
||||
|
@ -377,6 +403,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskPostOutputAlreadyExists', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
// Write a first time
|
||||
$this->assertTrue($this->taskStorage->writePostOutput($dummyTask, 'output', 'errors', 100, 0));
|
||||
|
@ -393,6 +420,7 @@ class TaskStorageTest extends TestCase
|
|||
{
|
||||
// Prepare a dummy task
|
||||
$dummyTask = new Task('testWriteAndReadTaskPostOutputNotExist', 'none');
|
||||
$this->taskStorage->addTask($dummyTask);
|
||||
|
||||
$this->assertNull($this->taskStorage->readPostOutput($dummyTask));
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ $configurator->addComponent(new \FuzeWorks\MVCRComponent());
|
|||
// Add Async library
|
||||
$configurator->deferComponentClassMethod('libraries', 'addLibraryClass', null, 'async', '\FuzeWorks\Async\Tasks');
|
||||
|
||||
// Debug
|
||||
$configurator->addDirectory(dirname(__FILE__), 'controllers', Priority::HIGH);
|
||||
// Add test directory so that config.tasks.php can be loaded
|
||||
$configurator->addDirectory(dirname(__FILE__), 'config', Priority::HIGH);
|
||||
|
||||
// Create container
|
||||
$container = $configurator->createContainer();
|
||||
|
|
|
@ -33,35 +33,42 @@
|
|||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Core;
|
||||
|
||||
return array(
|
||||
// Add a file lock
|
||||
'lock' => true,
|
||||
|
||||
// Which SuperVisor should be used
|
||||
'SuperVisor' => [
|
||||
'type' => 'ParallelSuperVisor',
|
||||
'type' => Core::getEnv('SUPERVISOR_TYPE', 'ParallelSuperVisor'),
|
||||
'parameters' => []
|
||||
],
|
||||
'TaskStorage' => [
|
||||
'type' => 'ArrayTaskStorage',
|
||||
'type' => Core::getEnv('TASKSTORAGE_TYPE', 'DummyTaskStorage'),
|
||||
|
||||
// For ArrayTaskStorage, first parameter is the file location of the array storage
|
||||
'parameters' => [
|
||||
'filename' => 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
|
||||
#]
|
||||
'parameters' => [
|
||||
// Type can be 'tcp' or 'unix'
|
||||
'socket_type' => Core::getEnv('TASKSTORAGE_REDIS_SOCKET_TYPE', 'tcp'),
|
||||
// If socket_type == 'unix', set the socket here
|
||||
'socket' => Core::getEnv('TASKSTORAGE_REDIS_SOCKET', null),
|
||||
// If socket_type == 'tcp', set the host here
|
||||
'host' => Core::getEnv('TASKSTORAGE_REDIS_HOST', '127.0.0.1'),
|
||||
// And some standard settings
|
||||
'password' => Core::getEnv('TASKSTORAGE_REDIS_PASSWORD', null),
|
||||
'port' => Core::getEnv('TASKSTORAGE_REDIS_PORT', 6379),
|
||||
'timeout' => Core::getEnv('TASKSTORAGE_REDIS_TIMEOUT', 0),
|
||||
]
|
||||
],
|
||||
'Executor' => [
|
||||
'type' => 'ShellExecutor',
|
||||
'type' => Core::getEnv('EXECUTOR_TYPE', 'ShellExecutor'),
|
||||
|
||||
// For ShellExecutor, first parameter is the file location of the worker script
|
||||
'parameters' => [
|
Loading…
Reference in New Issue