Skip to content

Commit

Permalink
Add TimeoutException
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed Apr 6, 2021
1 parent f389075 commit e3ad475
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 4 additions & 7 deletions demos/demoTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
*/
PMVC\Load::plug(
[
'error'=>['all'],
'debug'=>['output'=>'debug_cli', 'level'=> 'debug'],
'dev'=>null,
'supervisor'=>null,
'supervisor'=>['debug' => 'debug'],
],
['../../']
['../../', __DIR__.'/../vendor/pmvc-plugin/', ]
);

$parallel = new Parallel(function(){
Expand All @@ -30,9 +27,9 @@
'pid' => $parallel->getPid()
]);
},
'onFinish'=> function($parallel, $isCancel) {
'onFinish'=> function($parallel, $result) {
\PMVC\v([
'cancel' => $isCancel,
'result' => $result,
'pid' => $parallel->getPid()
]);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Timeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace PMVC\PlugIn\supervisor;

use RuntimeException;

class TimeoutException extends RuntimeException {}

class Timeout extends Parallel
{
public $type = TIMEOUT;

public function __construct($pid, $props)
{
parent::__construct(
Expand All @@ -26,6 +32,7 @@ function () {
return $plug->log('Kill by timeout...' . $pid);
}, DEBUG);
pcntl_signal_dispatch();
throw new TimeoutException($pid.' Timeout.');
},
[
SIGNAL => SIGKILL,
Expand Down

0 comments on commit e3ad475

Please sign in to comment.