Skip to content

Commit

Permalink
Merge pull request #7 from toplan/dev
Browse files Browse the repository at this point in the history
add new feature: destroy task
  • Loading branch information
toplan committed Apr 14, 2016
2 parents 8434b3e + 166c39e commit 32914c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions 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.4.1'
composer require 'toplan/task-balancer:~0.4.2'
```

# Usage
Expand Down Expand Up @@ -179,7 +179,7 @@ get data value of task instance.
| beforeCreateDriver | $task, $preReturn, $index, $handlers | no effect |
| afterCreateDriver | $task, $preReturn, $index, $handlers | no effect |
| beforeRun | $task, $preReturn, $index, $handlers | if `false` will stop run task and return `false` |
| beforeDriverRun | $task, $driver, $preReturn, $index, $handlers | if `false` will stop run current driver and try to use next backup driver |
| beforeDriverRun | $task, $driver, $preReturn, $index, $handlers | if `false` will stop to use current driver and try to use next backup driver |
| afterDriverRun | $task, $driverResult, $preReturn, $index, $handlers | no effect |
| afterRun | $task, $taskResult, $preReturn, $index, $handlers | if not boolean will override result value |

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.4.1",
"version": "0.4.2",
"keywords": ["task", "balance", "load balancing", "balancer"],
"authors": [
{
Expand Down
17 changes: 17 additions & 0 deletions src/TaskBalancer/Balancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,21 @@ public static function getTask($name)
return self::$tasks[$name];
}
}

/**
* destroy a task.
*
* @param $name
*/
public static function destroy($name)
{
if (is_array($name)) {
foreach ($name as $v) {
self::destroy($v);
}
} elseif (is_string($name) && self::hasTask($name)) {
self::$tasks[$name] = null;
unset(self::$tasks[$name]);
}
}
}
5 changes: 4 additions & 1 deletion src/TaskBalancer/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function runDriver($name)
// before run a driver, call 'beforeDriverRun' hooks,
// but current driver value is already change to this driver.
// If 'beforeDriverRun' hook return false,
// will stop use current driver and try to use next driver
// will stop to use current driver and try to use next driver
$currentDriverEnable = $this->callHookHandler('beforeDriverRun', $driver);
if (!$currentDriverEnable) {
return $this->tryNextDriver();
Expand Down Expand Up @@ -483,6 +483,9 @@ public function reset()
{
$this->status = null;
$this->results = null;
$this->currentDriver = null;
$this->time['started_at'] = 0;
$this->time['finished_at'] = 0;

return $this;
}
Expand Down

0 comments on commit 32914c1

Please sign in to comment.