diff --git a/README.md b/README.md index b6bf7dc..f67146d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ lightweight and powerful task load balancing for php # Install ```php - composer require 'toplan/task-balancer:~0.1.3' + composer require 'toplan/task-balancer:~0.1.4' ``` # Usage diff --git a/composer.json b/composer.json index d4e1af9..b4b9e01 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "toplan/task-balancer", "description": "lightweight and powerful task load balancing for php (like the nginx load balancing)", "license": "MIT", - "version": "0.1.3", + "version": "0.1.4", "keywords": ["task", "balance", "load balancing", "balancer"], "authors": [ { diff --git a/src/TaskBalancer/Task.php b/src/TaskBalancer/Task.php index db9e6bc..da3a840 100644 --- a/src/TaskBalancer/Task.php +++ b/src/TaskBalancer/Task.php @@ -178,7 +178,11 @@ protected function afterRun($success) $this->status = static::FINISHED; $this->time['finished_at'] = microtime(); $data = $this->callHookHandler('afterRun', $this->results); - return is_bool($data) ? $this->results : $data; + $return = []; + $return['success'] = $success; + $return['time'] = $this->time; + $return['logs'] = $this->results; + return is_bool($data) ? $return : $data; } /** diff --git a/test/demo.php b/test/demo.php index 0da0ccd..872fd9e 100644 --- a/test/demo.php +++ b/test/demo.php @@ -1,5 +1,9 @@ '20' ]; $t = Balancer::task('test1', $data, function($task){ - $task->driver('driver_1 100 backup', function($driver, $data){ + $task->driver('driver_1 100', 'backup', function($driver, $data){ $person = new Person($data['name'], $data['age']); $driver->failed(); print_r('run work! by '.$driver->name.'
'); @@ -27,7 +31,7 @@ ->weight(0)->backUp() ->data(['this is data 3']) ->work(function($driver, $data){ - $driver->failed(); + $driver->success(); print_r('run work! by '.$driver->name.'
'); return ['test.driver3 working', $data]; }); @@ -38,7 +42,6 @@ $task->afterRun(function($task, $results){ print_r('after run --------!
'); - return $results; }); });