Do task, rollback if something goes wrong. Just like database transactions.

Do task, rollback if something goes wrong. Just like database transactions.

README

Latest Version
Software License
Build Status
Coverage Status
Quality Score

Installation

composer require rap2hpoutre/nestor

Usage

Run some tasks. In this example, the second task fails, everything will be rolled back.

$nestor = new NestorServant;

// Create 1st task
$nestor->task()
    ->up(function (){
        echo "task 1 donen";
    })
    ->down(function () {
        echo "task 1 cancelledn";
    });
    
// Create 2nd task (will fail)
$nestor->task()
    ->up(function ($nestor) {
        $nestor->fail();
        echo "task 2 donen";
    })
    ->down(function () {
        echo "task 2 cancelledn";
    });
    
// Run all tasks, rollback on fail (LIFO stack)
$nestor->run();

You should see:

task 1 done
task 2 cancelled
task 1 cancelled

Why?

Todo: Explain why.

About

Software License

Thanks to DonoSybrix. Feel free to contribute.

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *