Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cgauge/task-manager-lib
Task Manager Library
https://github.com/cgauge/task-manager-lib
Last synced: about 2 months ago
JSON representation
Task Manager Library
- Host: GitHub
- URL: https://github.com/cgauge/task-manager-lib
- Owner: cgauge
- License: lgpl-3.0
- Created: 2019-06-06T12:35:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-20T13:54:46.000Z (over 1 year ago)
- Last Synced: 2024-09-24T16:46:54.979Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 61.5 KB
- Stars: 3
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Task Manager ⚙️
# Installation
```bash
composer require customergauge/task-manager
```
# Usage## Execute a task
```php
use CustomerGauge\TaskManager\Task;
use CustomerGauge\TaskManager\TaskManager;class SimpleTask implements Task
{
public function run(array $attributes) : array
{
echo "simple task";
}
}$taskManager = new TaskManager; // defaults to StopOnFailure strategy
$taskManager->add(new SimpleTask);$taskManager->run([]);
// output: simple task
```
## Continue on failure strategy```php
use CustomerGauge\TaskManager\Task;
use CustomerGauge\TaskManager\TaskManager;
use CustomerGauge\TaskManager\Strategy\ContinueOnFailure;class FirstTask implements Task
{
public function run(array $attributes) : array
{
throw new Exception;
}
}class SecondTask implements Task
{
public function run(array $attributes) : array
{
echo "second task";
}
}$taskManager = new TaskManager(new ContinueOnFailure);
$taskManager->add(new FirstTask)
->add(new SecondTask);$taskManager->run([]);
// output: second task
```## Rollback executed tasks
```php
use CustomerGauge\TaskManager\Task;
use CustomerGauge\TaskManager\Reversible;
use CustomerGauge\TaskManager\TaskManager;
use CustomerGauge\TaskManager\Strategy\RollbackOnFailure;class FirstTask implements Task, Reversible
{
public function run(array $attributes) : array
{
echo "first task";
}public function reverse(array $attributes)
{
echo "reverse first task";
}
}class SecondTask implements Task
{
public function run(array $attributes) : array
{
throw new Exception;
}
}$taskManager = new TaskManager(new RollbackOnFailure);
$taskManager->add(new FirstTask)
->add(new SecondTask);$taskManager->run([]);
/*
output:
firt task
reverse first task
*/
```# Contributing
Contributions are always welcome, please have a look at our issues to see if there's something you could help with.
# License
Task Manager Library is licensed under LGPLv3 license.