Skip to content

Commit

Permalink
update task method run() return value
Browse files Browse the repository at this point in the history
  • Loading branch information
toplan committed Dec 5, 2015
1 parent 2871fe2 commit 980ad6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
6 changes: 5 additions & 1 deletion src/TaskBalancer/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions test/demo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php
require('../vendor/autoload.php');
//require('../vendor/autoload.php');
require('../src/TaskBalancer/Balancer.php');
require('../src/TaskBalancer/Driver.php');
require('../src/TaskBalancer/Task.php');
require('../src/TaskBalancer/TaskBalancerException.php');

use Toplan\TaskBalance\Balancer;

Expand All @@ -9,7 +13,7 @@
'age' => '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.'<br>');
Expand All @@ -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.'<br>');
return ['test.driver3 working', $data];
});
Expand All @@ -38,7 +42,6 @@

$task->afterRun(function($task, $results){
print_r('after run --------!<br>');
return $results;
});
});

Expand Down

0 comments on commit 980ad6e

Please sign in to comment.