Skip to content

Commit

Permalink
Add sync task demo
Browse files Browse the repository at this point in the history
  • Loading branch information
stelin committed Jul 16, 2019
1 parent b5dab89 commit ec938e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
10 changes: 0 additions & 10 deletions src/task/src/Swoole/SyncFinishListener.php

This file was deleted.

3 changes: 3 additions & 0 deletions src/task/src/Swoole/SyncTaskListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class SyncTaskListener implements SyncTaskInterface
private $dispatcher;

/**
* Dispatch
*
* @param Server $server
* @param int $taskId
* @param int $srcWorkerId
Expand All @@ -39,6 +41,7 @@ class SyncTaskListener implements SyncTaskInterface
*/
public function onTask(Server $server, $taskId, int $srcWorkerId, $data)
{
// Task params
[$type, $name, $method, $params, $ext] = Packet::unpack($data);

return $this->dispatcher->dispatch($type, $name, $method, $params, $ext);
Expand Down
6 changes: 5 additions & 1 deletion src/task/src/SyncTaskDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
class SyncTaskDispatcher
{
/**
* Dispatch
*
* @param string $type
* @param string $name
* @param string $method
Expand All @@ -45,6 +47,8 @@ public function dispatch(string $type, string $name, string $method, array $para
}

/**
* Handle task
*
* @param string $name
* @param string $method
* @param array $params
Expand Down Expand Up @@ -72,7 +76,7 @@ private function handle(string $name, string $method, array $params)
$object = BeanFactory::getBean($className);
if (!method_exists($object, $methodName)) {
throw new TaskException(
sprintf('Task(name=%s method=%s) is not exist!', $name, $method)
sprintf('Task(name=%s method=%s) method is not exist!', $name, $method)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/task/src/TaskDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private function handle(Request $request)
$object = BeanFactory::getBean($className);
if (!method_exists($object, $methodName)) {
throw new TaskException(
sprintf('Task(name=%s method=%s) is not exist!', $name, $method)
sprintf('Task(name=%s method=%s) method is not exist!', $name, $method)
);
}

Expand Down

0 comments on commit ec938e5

Please sign in to comment.