Skip to content

Commit 931adef

Browse files
committed
fixes #7, proper SIGTERM handling for daemon
1 parent 6fc4d22 commit 931adef

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

commands/AsyncWorkerCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ public function actionExecute($queueName = null, $count = null)
3535
*/
3636
public function actionDaemon($queueName = null, $count = null)
3737
{
38-
$this->handleSignal();
39-
4038
/** @var AsyncTask $task */
4139
while ($task = \Yii::$app->async->receiveTask($queueName ?: AsyncTask::$queueName, true)) {
42-
$this->checkSignal();
40+
$this->handleSignal();
4341

4442
$task::$queueName = $queueName ?: AsyncTask::$queueName;
4543
$this->processTask($task);
4644

4745
if (($count !== null && !--$count) || $this->checkSignal()) {
4846
break;
4947
}
48+
49+
// we don't want to ignore SIGTERM while waiting for task
50+
$this->removeSignalHandler();
5051
}
5152
}
5253

@@ -68,6 +69,11 @@ function ($signo) {
6869
);
6970
}
7071

72+
private function removeSignalHandler()
73+
{
74+
pcntl_signal(SIGTERM, SIG_DFL);
75+
}
76+
7177
private function checkSignal()
7278
{
7379
pcntl_signal_dispatch();

0 commit comments

Comments
 (0)