Skip to content

Accrossan/step-execute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Accrossan Step Execute

A robust, fluent step execution engine for Laravel applications. safely execute a series of steps with optional transaction support, error handling, and rollback capabilities.

Features

  • Fluent Interface: Chain steps together easily.
  • Transaction Support: Wrap execution in a database transaction with automatic retry on deadlocks.
  • Error Handling: Custom exception handlers per step.
  • Execution Logging: Detailed logs of execution steps and timing.
  • State Passing: Pass results from one step to the next.

Installation

composer require accrossan/step-execute

Usage

Basic Usage

use Accrossan\StepExecute\StepExecute;

$result = StepExecute::create()
    ->step('validate', function () {
        // Validation logic
        return ['valid' => true];
    })
    ->step('process', function ($previousResult) {
        // Use result from previous step
        return 'Processed';
    })
    ->execute();

With Database Transaction

Automatically wraps steps in a transaction and retries on deadlocks.

$result = StepExecute::createWithTransaction()
    ->step('create_user', function () {
        return User::create([...]);
    })
    ->step('create_profile', function ($user) {
        return Profile::create(['user_id' => $user->id]);
    })
    ->execute();

Exception Handling

StepExecute::create()
    ->step(
        'risky_operation',
        fn() => throw new Exception('Fail'),
        function ($e, $stepName, $prevResult) {
            // Handle error, maybe return a fallback value
            return 'fallback';
        }
    )
    ->execute();

Lifecycle Callbacks

StepExecute::createWithTransaction()
    ->beforeTransaction(fn() => Log::info('Starting...'))
    ->onRollback(fn($e) => Log::error('Rolled back: ' . $e->getMessage()))
    ->afterTransaction(fn($res) => Log::info('Done!'))
    ->finally(fn($results) => Log::info('Cleanup'))
    ->execute();

License

Commercial / Proprietary License

Copyright (c) Accrossan. All rights reserved.

About

A robust step execution engine with transaction support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages