#### 问题描述
我有一些任务是周期性执行的,并且时间比较长。当我退出的时候,我希望当前任务执行完才退出
#### 为此你搜索到了哪些方案及不适用的原因
stop_timeout没效果 他执行完会开启下一个任务
#### 已经解决
```php
namespace app\process;
use support\Db;
use Workerman\Worker;
class FooProcess
{
private bool $isExit = false;
public function onWorkerStart()
{
echo "启动".PHP_EOL;
pcntl_async_signals(true);
pcntl_signal(SIGTERM, function (){
echo "SIGTERM".PHP_EOL;
$this->isExit = true;
});
pcntl_signal(SIGINT, function (){
echo "SIGINT".PHP_EOL;
$this->isExit = true;
});
while (!$this->isExit){
$this->doJob();
!$this->isExit && sleep(10);
}
Worker::stopAll();
}
public function onWorkerReload()
{
echo "重启".PHP_EOL;
$this->isExit = true;
}
private function doJob()
{
echo "开始执行".PHP_EOL;
$i = 0;
while ($i < 10){
echo "执行中".$i.PHP_EOL;
Db::table('demo')
->selectRaw('sleep(1)')
->get();
$i++;
}
echo "执行结束".PHP_EOL;
}
}
```