From e3ad4755299d9be68e19a572138593f6a5422343 Mon Sep 17 00:00:00 2001 From: Hill Date: Tue, 6 Apr 2021 21:34:57 +0000 Subject: [PATCH] Add TimeoutException --- demos/demoTimeout.php | 11 ++++------- src/Timeout.php | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/demos/demoTimeout.php b/demos/demoTimeout.php index ac68b8a..d5db433 100644 --- a/demos/demoTimeout.php +++ b/demos/demoTimeout.php @@ -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(){ @@ -30,9 +27,9 @@ 'pid' => $parallel->getPid() ]); }, - 'onFinish'=> function($parallel, $isCancel) { + 'onFinish'=> function($parallel, $result) { \PMVC\v([ - 'cancel' => $isCancel, + 'result' => $result, 'pid' => $parallel->getPid() ]); } diff --git a/src/Timeout.php b/src/Timeout.php index 63d84a7..6f9aafb 100644 --- a/src/Timeout.php +++ b/src/Timeout.php @@ -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( @@ -26,6 +32,7 @@ function () { return $plug->log('Kill by timeout...' . $pid); }, DEBUG); pcntl_signal_dispatch(); + throw new TimeoutException($pid.' Timeout.'); }, [ SIGNAL => SIGKILL,