@@ -8,12 +8,12 @@ lightweight and powerful task load balancing for php
88- Support multiple drives for every task.
99- Automatically choose a driver to execute task by drivers` weight value.
1010- Support multiple backup drivers.
11- - Task lifecycle and hooks.
11+ - Task lifecycle and hooks system .
1212
1313# Install
1414
1515``` php
16- composer require 'toplan/task-balancer:~0.2.0 '
16+ composer require 'toplan/task-balancer:~0.2.1 '
1717```
1818
1919# Usage
@@ -59,13 +59,18 @@ The `$result` structure:
5959[
6060 'success' => true,
6161 'time' => [
62- 'started_at' => '' ,
63- 'finished_at' => ''
62+ 'started_at' => timestamp ,
63+ 'finished_at' => timestamp
6464 ],
6565 'logs' => [
6666 '0' => [
67- 'driver' => 'Luosimao',
68- ...
67+ 'driver' => 'driver_1',
68+ 'success' => false,
69+ 'time' => [
70+ 'started_at' => timestamp,
71+ 'finished_at' => timestamp
72+ ],
73+ 'result' => 'some data here'
6974 ],
7075 ...
7176 ]
@@ -168,12 +173,12 @@ get data value of task instance.
168173
169174| Hook name | handler arguments | influence of the last handler`s return value |
170175| --------- | :----------------: | :-----: |
171- | beforeCreateDriver | $task, $preReturn, $index | no effect |
172- | afterCreateDriver | $task, $preReturn, $index | no effect |
173- | beforeRun | $task, $preReturn, $index | if ` false ` will stop run task and return ` false ` |
174- | beforeDriverRun | $task, $preReturn, $index | no effect |
175- | afterDriverRun | $task, $preReturn, $index | no effect |
176- | afterRun | $task, $results , $preReturn, $index | if not boolean will override result value |
176+ | beforeCreateDriver | $task, $preReturn, $index, $count | no effect |
177+ | afterCreateDriver | $task, $preReturn, $index, $count | no effect |
178+ | beforeRun | $task, $preReturn, $index, $count | if ` false ` will stop run task and return ` false ` |
179+ | beforeDriverRun | $task, $preReturn, $index, $count | no effect |
180+ | afterDriverRun | $task, $preReturn, $index, $count | no effect |
181+ | afterRun | $task, $taskResult , $preReturn, $index, $count | if not boolean will override result value |
177182
178183###Use Hooks
179184
@@ -196,20 +201,24 @@ get data value of task instance.
196201
197202``` php
198203//example
199- $task->beforeRun(function($task, $preReturn, $index ){
204+ $task->beforeRun(function($task, $preReturn, $index, $count ){
200205 //what is $preReturn?
201- echo $preReturn == null; //true
206+ $preReturn == null; //true
202207 //what is $index?
203- echo $index == 0; //true
208+ $index == 0; //true
209+ //what is $count?
210+ echo $count; //2
204211 //do something..
205212 return 'beforeRun_1';
206213}, false);
207214
208- $task->beforeRun(function($task, $preReturn, $index ){
215+ $task->beforeRun(function($task, $preReturn, $index, $count ){
209216 //what is $preReturn?
210- echo $preReturn == 'beforeRun_1'; //true
217+ $preReturn == 'beforeRun_1'; //true
211218 //what is $index?
212- echo $index == 1; //true
219+ $index == 1; //true
220+ //what is $count?
221+ echo $count; //2
213222 //do other something..
214223}, false);
215224```
0 commit comments