PHP code example of customergauge / task-manager

1. Go to this page and download the library: Download customergauge/task-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

customergauge / task-manager example snippets


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 

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

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
*/