All Projects β†’ toplan β†’ Task Balancer

toplan / Task Balancer

Licence: mit
🎲Task load balancing for php (like the nginx load balancing)

Projects that are alternatives of or similar to Task Balancer

Dobi
A build automation tool for Docker applications
Stars: ✭ 269 (+484.78%)
Mutual labels:  task-runner
Realize
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.
Stars: ✭ 4,162 (+8947.83%)
Mutual labels:  task-runner
Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
Stars: ✭ 727 (+1480.43%)
Mutual labels:  task-runner
Air
☁️ Live reload for Go apps
Stars: ✭ 5,257 (+11328.26%)
Mutual labels:  task-runner
Yotaq
yotaq - Your Own Task Queue for Python
Stars: ✭ 339 (+636.96%)
Mutual labels:  task-runner
Godo
golang build tool in the spirt of rake, gulp
Stars: ✭ 523 (+1036.96%)
Mutual labels:  task-runner
myke
make with yaml: development tasks made simple with golang, yaml and many ingredients
Stars: ✭ 67 (+45.65%)
Mutual labels:  task-runner
Bake
Bake is a bash task runner
Stars: ✭ 27 (-41.3%)
Mutual labels:  task-runner
Cron Manager
A PHP cron task manager for MVC-type applications
Stars: ✭ 396 (+760.87%)
Mutual labels:  task-runner
Cr
Runs your tasks at maximum concurrency
Stars: ✭ 681 (+1380.43%)
Mutual labels:  task-runner
Task
A task runner / simpler Make alternative written in Go
Stars: ✭ 4,282 (+9208.7%)
Mutual labels:  task-runner
Celery
Distributed Task Queue (development branch)
Stars: ✭ 18,378 (+39852.17%)
Mutual labels:  task-runner
Awesome Npm Scripts
Everything awesome related to npm scripts and using npm as a build tool.
Stars: ✭ 600 (+1204.35%)
Mutual labels:  task-runner
Phulp
The task manager for php
Stars: ✭ 294 (+539.13%)
Mutual labels:  task-runner
Cargo Make
Rust task runner and build tool.
Stars: ✭ 895 (+1845.65%)
Mutual labels:  task-runner
makesure
Simple task/command runner with declarative goals and dependencies
Stars: ✭ 230 (+400%)
Mutual labels:  task-runner
Mask
🎭 A CLI task runner defined by a simple markdown file
Stars: ✭ 495 (+976.09%)
Mutual labels:  task-runner
Doit
task management & automation tool
Stars: ✭ 972 (+2013.04%)
Mutual labels:  task-runner
Deployer
Deployer is a free and open source deployment tool.
Stars: ✭ 854 (+1756.52%)
Mutual labels:  task-runner
Frontend Cheat Sheets
Collection of cheat sheets(HTML, CSS, JS, Git, Gulp, etc.,) for your frontend development needs & reference
Stars: ✭ 604 (+1213.04%)
Mutual labels:  task-runner

Intro

Latest Stable Version Total Downloads

Lightweight and powerful task load balancing.

like the nginx load balancing πŸ˜„

Features

  • Support multiple drives for every task.
  • Automatically choose a driver to execute task by drivers' weight value.
  • Support multiple backup drivers.
  • Task lifecycle and hooks system.

Install

composer require toplan/task-balancer:~0.5

Usage

//define a task
Balancer::task('task1', function($task){
    //define a driver for current task like this:
    $task->driver('driver_1 100 backup', function ($driver, $data) {
        //do something here
        ...
        //set whether run success/failure at last
        if ($success) {
            $driver->success();
        } else {
            $driver->failure();
        }
        //return some data you need
        return 'some data you need';
    });

    //or like this:
    $task->driver('driver_2', 90, function ($driver, $data) {
        //...same as above..
    })->data(['this is data 2']);

    //or like this:
    $task->driver('driver_3')
    ->weight(0)->backUp()
    ->data(['this is data 3'])
    ->work(function ($driver, $data) {
        //...same as above..
    });
});

//run the task
$result = Balancer::run('task1');

The $result structure:

[
    'success' => true,
    'time' => [
        'started_at' => timestamp,
        'finished_at' => timestamp
    ],
    'logs' => [
        '0' => [
            'driver' => 'driver_1',
            'success' => false,
            'time' => [
                'started_at' => timestamp,
                'finished_at' => timestamp
            ],
            'result' => 'some data you need'
        ],
        ...
    ]
]

API

Balancer

Balancer::task($name[, $data][, Closure $ready]);

Create a task instance, and return it. The closure $ready immediately called with argument $task.

Balancer::task('taskName', $data, function($task){
    //task's ready work, such as create drivers.
});

$data will store in the task instance.

Balancer::run($name[, array $options])

Run the task by name, and return the result data.

The keys of $options:

  • data
  • driver

Task

name($name)

set the name of task.

data($data)

Set the data of task.

driver($config[, $weight][, 'backup'], Closure $work)

Create a driver for the task. The closure $work will been called with arguments $driver and $data.

Expected $weight to be a integer, default 1.

$task->driver('driverName 80 backup', function($driver, $data){
    //driver's job content.
});

hasDriver($name)

Whether has the specified driver.

getDriver($name)

Get driver by name.

removeDriver($name)

Remove driver from drivers' pool by name.

Driver

weight($weight)

Set the weight value of driver.

backup($is)

Set whether backup driver.

Expected $is to be boolean, default true.

data($data)

Set the data of driver.

$data will store in driver instance.

work(Closure $work);

Set the job content of driver.

$data equals to $driver->getData()

reset($config[, $weight][, 'backup'], Closure $work)

Reset driver's weight value, job content and reset whether backup.

destroy()

Remove the driver from task which belongs to.

failure()

Set the driver running failure.

success()

Set the driver run successfully.

getDriverData()

Get the data which store in driver instance.

getTaskData()

Get the data which store in task instance.

Lifecycle & Hooks

Support multiple handlers for every hooks!

Hooks

Hook name handler arguments influence of the last handler's return value
beforeCreateDriver $task, $props, $index, &$handlers, $prevReturn if an array will been merged into original props
afterCreateDriver $task, $driver, $index, &$handlers, $prevReturn -
beforeRun $task, $index, &$handlers, $prevReturn if false will stop run task and return false
beforeDriverRun $task, $driver, $index, &$handlers, $prevReturn if false will stop to use current driver and try to use next backup driver
afterDriverRun $task, $driverResult, $index, &$handlers, $prevReturn -
afterRun $task, $taskResult, $index, &$handlers, $prevReturn if not boolean will override result value

Usage

  • $task->hook($hookName, $handler, $override)

  • $task->beforeCreateDriver($handler, $override)

  • $task->afterCreateDriver($handler, $override)

  • $task->beforeRun($handler, $override)

  • $task->beforeDriverRun($handler, $override)

  • $task->afterDriverRun($handler, $override)

  • $task->afterRun($handler, $override)

$override default false.

//example
$task->beforeRun(function($task, $index, $handlers, $prevReturn){
    //what is $prevReturn?
    echo $prevReturn == null; //true
    //what is $index?
    echo $index == 0; //true
    //what is $handlers?
    echo count($handlers); //2
    //do something..
    return 'beforeRun_1';
}, false);

$task->beforeRun(function($task, $index, $handlers, $prevReturn){
    //what is $prevReturn?
    echo $prevReturn == 'beforeRun_1'; //true
    //what is $index?
    echo $index == 1; //true
    //what is $handlers?
    echo count($handlers); //2
    //do other something..
}, false);

Dependents

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].