@@ -8,12 +8,12 @@ lightweight and powerful task load balancing for php
8
8
- Support multiple drives for every task.
9
9
- Automatically choose a driver to execute task by drivers` weight value.
10
10
- Support multiple backup drivers.
11
- - Task lifecycle and hooks.
11
+ - Task lifecycle and hooks system .
12
12
13
13
# Install
14
14
15
15
``` php
16
- composer require 'toplan/task-balancer:~0.2.0 '
16
+ composer require 'toplan/task-balancer:~0.2.1 '
17
17
```
18
18
19
19
# Usage
@@ -59,13 +59,18 @@ The `$result` structure:
59
59
[
60
60
'success' => true,
61
61
'time' => [
62
- 'started_at' => '' ,
63
- 'finished_at' => ''
62
+ 'started_at' => timestamp ,
63
+ 'finished_at' => timestamp
64
64
],
65
65
'logs' => [
66
66
'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'
69
74
],
70
75
...
71
76
]
@@ -168,12 +173,12 @@ get data value of task instance.
168
173
169
174
| Hook name | handler arguments | influence of the last handler`s return value |
170
175
| --------- | :----------------: | :-----: |
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 |
177
182
178
183
###Use Hooks
179
184
@@ -196,20 +201,24 @@ get data value of task instance.
196
201
197
202
``` php
198
203
//example
199
- $task->beforeRun(function($task, $preReturn, $index ){
204
+ $task->beforeRun(function($task, $preReturn, $index, $count ){
200
205
//what is $preReturn?
201
- echo $preReturn == null; //true
206
+ $preReturn == null; //true
202
207
//what is $index?
203
- echo $index == 0; //true
208
+ $index == 0; //true
209
+ //what is $count?
210
+ echo $count; //2
204
211
//do something..
205
212
return 'beforeRun_1';
206
213
}, false);
207
214
208
- $task->beforeRun(function($task, $preReturn, $index ){
215
+ $task->beforeRun(function($task, $preReturn, $index, $count ){
209
216
//what is $preReturn?
210
- echo $preReturn == 'beforeRun_1'; //true
217
+ $preReturn == 'beforeRun_1'; //true
211
218
//what is $index?
212
- echo $index == 1; //true
219
+ $index == 1; //true
220
+ //what is $count?
221
+ echo $count; //2
213
222
//do other something..
214
223
}, false);
215
224
```
0 commit comments