-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
167 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace pms\Task; | ||
/** | ||
* 任务基类 | ||
* Class Task | ||
* @package pms\Task | ||
*/ | ||
class Task | ||
{ | ||
protected $swoole_server; | ||
protected $trueData; | ||
protected $data; | ||
protected $task_id; | ||
protected $src_worker_id; | ||
|
||
|
||
public function __construct($swoole_server, $data) | ||
{ | ||
$this->swoole_server = $swoole_server; | ||
$this->trueData = $data; | ||
$this->data = $data['data'] ? $data['data'] : $data[0]; | ||
} | ||
|
||
/** | ||
* 设置任务进程id | ||
* @param $task_id | ||
*/ | ||
public function setTaskId($task_id) | ||
{ | ||
$this->task_id = $task_id; | ||
} | ||
|
||
/** | ||
* 设置任务进程id | ||
* @param $task_id | ||
*/ | ||
public function setWorkId($src_worker_id) | ||
{ | ||
$this->src_worker_id = $src_worker_id; | ||
} | ||
|
||
|
||
/** | ||
* 执行方法 | ||
* @return mixed | ||
*/ | ||
final public function execute() | ||
{ | ||
$startTime = microtime(true); | ||
$re = $this->run(); | ||
$endTime = microtime(true); | ||
|
||
$data = $this->trueData; | ||
$data['re'] = $re; | ||
$data['task_id'] = $this->task_id; | ||
$data['time'] = $endTime - $startTime; | ||
return $data; | ||
} | ||
|
||
final public function finish() | ||
{ | ||
$startFinishTime = microtime(true); | ||
$re = $this->end(); | ||
$endFinishTime = microtime(true); | ||
$data = $this->trueData; | ||
$data['re'] = $re; | ||
$data['task_id'] = $this->task_id; | ||
$data['time'] = $endFinishTime - $startFinishTime; | ||
return $data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace pms\Task; | ||
|
||
interface TaskInterface | ||
{ | ||
public function run(); | ||
|
||
public function end(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.