From e58a2dee98774efd4ade0364cee2e6ee934b6e69 Mon Sep 17 00:00:00 2001 From: dimanzver Date: Wed, 26 Apr 2023 22:07:02 +0300 Subject: [PATCH 1/8] add pcntl_signal_dispatch after job finish for php extension --- src/drivers/amqp_interop/Queue.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/drivers/amqp_interop/Queue.php b/src/drivers/amqp_interop/Queue.php index 8b99a5488..555e260d5 100644 --- a/src/drivers/amqp_interop/Queue.php +++ b/src/drivers/amqp_interop/Queue.php @@ -305,6 +305,10 @@ public function listen() $this->redeliver($message); + if (function_exists('pcntl_signal_dispatch') && $consumer instanceof \Enqueue\AmqpExt\AmqpConsumer) { + pcntl_signal_dispatch(); + } + return true; } @@ -319,6 +323,10 @@ public function listen() $this->redeliver($message); } + if (function_exists('pcntl_signal_dispatch') && $consumer instanceof \Enqueue\AmqpExt\AmqpConsumer) { + pcntl_signal_dispatch(); + } + return true; }; From 0ee4e160c0778380eac501f80ffe2682da5ba94f Mon Sep 17 00:00:00 2001 From: dimanzver Date: Thu, 27 Apr 2023 17:31:57 +0300 Subject: [PATCH 2/8] update package name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 917464c6c..bf47f9d86 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "yiisoft/yii2-queue", + "name": "dimanzver/yii2-queue", "description": "Yii2 Queue Extension which supported DB, Redis, RabbitMQ, Beanstalk, SQS and Gearman", "type": "yii2-extension", "keywords": ["yii", "queue", "async", "gii", "db", "redis", "rabbitmq", "beanstalk", "gearman", "sqs"], From 97ba157a55f6848cf897490b06660ea0bf15bd9d Mon Sep 17 00:00:00 2001 From: dimanzver Date: Sun, 18 Jun 2023 14:40:28 +0300 Subject: [PATCH 3/8] remove ugly signal handling fix, don`t process signals for amqp extension --- src/drivers/amqp_interop/Queue.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/drivers/amqp_interop/Queue.php b/src/drivers/amqp_interop/Queue.php index 62234f09d..c6a2f3113 100644 --- a/src/drivers/amqp_interop/Queue.php +++ b/src/drivers/amqp_interop/Queue.php @@ -279,7 +279,10 @@ public function init() $this->close(); }); - if (extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7) { + if ( + extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 && + $this->driver !== self::ENQUEUE_AMQP_EXT + ) { // https://github.com/php-amqplib/php-amqplib#unix-signals $signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP]; @@ -319,10 +322,6 @@ public function listen() $this->redeliver($message); - if (function_exists('pcntl_signal_dispatch') && $consumer instanceof \Enqueue\AmqpExt\AmqpConsumer) { - pcntl_signal_dispatch(); - } - return true; } @@ -337,10 +336,6 @@ public function listen() $this->redeliver($message); } - if (function_exists('pcntl_signal_dispatch') && $consumer instanceof \Enqueue\AmqpExt\AmqpConsumer) { - pcntl_signal_dispatch(); - } - return true; }; From 01a32b267aa6b25b130e222558540d3263fd59b6 Mon Sep 17 00:00:00 2001 From: dimanzver Date: Sun, 18 Jun 2023 17:58:14 +0300 Subject: [PATCH 4/8] Ignore signal for amqp extension while job is executing --- src/drivers/amqp_interop/Queue.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/drivers/amqp_interop/Queue.php b/src/drivers/amqp_interop/Queue.php index c6a2f3113..8de79b22e 100644 --- a/src/drivers/amqp_interop/Queue.php +++ b/src/drivers/amqp_interop/Queue.php @@ -325,6 +325,21 @@ public function listen() return true; } + // Ignore signal for amqp extension while job is executing + if ( + extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 && + $this->driver === self::ENQUEUE_AMQP_EXT + ) { + $signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP]; + + foreach ($signals as $signal) { + pcntl_signal($signal, static function ($signal) { + pcntl_signal($signal, SIG_DFL); + posix_kill(posix_getpid(), $signal); + }); + } + } + $ttr = $message->getProperty(self::TTR); $attempt = $message->getProperty(self::ATTEMPT, 1); @@ -336,6 +351,19 @@ public function listen() $this->redeliver($message); } + // For amqp extension: restore default signal handlers + if ( + extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 && + $this->driver === self::ENQUEUE_AMQP_EXT + ) { + pcntl_signal_dispatch(); + + $signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP]; + foreach ($signals as $signal) { + pcntl_signal($signal, SIG_DFL); + } + } + return true; }; From bd92d80998a593172cf6701f143253999974a8e2 Mon Sep 17 00:00:00 2001 From: dimanzver Date: Fri, 14 Jul 2023 20:32:21 +0300 Subject: [PATCH 5/8] fix exiting for docker --- src/drivers/amqp_interop/Queue.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/drivers/amqp_interop/Queue.php b/src/drivers/amqp_interop/Queue.php index 8de79b22e..627470af2 100644 --- a/src/drivers/amqp_interop/Queue.php +++ b/src/drivers/amqp_interop/Queue.php @@ -20,6 +20,7 @@ use Interop\Amqp\AmqpQueue; use Interop\Amqp\AmqpTopic; use Interop\Amqp\Impl\AmqpBind; +use Yii; use yii\base\Application as BaseApp; use yii\base\Event; use yii\base\NotSupportedException; @@ -298,8 +299,7 @@ public function init() $oldHandler($signal); } - pcntl_signal($signal, SIG_DFL); - posix_kill(posix_getpid(), $signal); + Yii::$app->end(); }); } } @@ -334,8 +334,7 @@ public function listen() foreach ($signals as $signal) { pcntl_signal($signal, static function ($signal) { - pcntl_signal($signal, SIG_DFL); - posix_kill(posix_getpid(), $signal); + Yii::$app->end(); }); } } From bc13f4c53b59b654791effeeca8abf770ddd4085 Mon Sep 17 00:00:00 2001 From: dimanzver Date: Sat, 15 Jul 2023 08:58:12 +0300 Subject: [PATCH 6/8] try run pcntl_signal_dispatch on start and end of job --- src/drivers/amqp_interop/Queue.php | 34 +++--------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/drivers/amqp_interop/Queue.php b/src/drivers/amqp_interop/Queue.php index 627470af2..e008b21c5 100644 --- a/src/drivers/amqp_interop/Queue.php +++ b/src/drivers/amqp_interop/Queue.php @@ -280,10 +280,7 @@ public function init() $this->close(); }); - if ( - extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 && - $this->driver !== self::ENQUEUE_AMQP_EXT - ) { + if (extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7) { // https://github.com/php-amqplib/php-amqplib#unix-signals $signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP]; @@ -317,6 +314,7 @@ public function listen() $consumer = $this->context->createConsumer($queue); $callback = function (AmqpMessage $message, AmqpConsumer $consumer) { + pcntl_signal_dispatch(); if ($message->isRedelivered()) { $consumer->acknowledge($message); @@ -325,20 +323,6 @@ public function listen() return true; } - // Ignore signal for amqp extension while job is executing - if ( - extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 && - $this->driver === self::ENQUEUE_AMQP_EXT - ) { - $signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP]; - - foreach ($signals as $signal) { - pcntl_signal($signal, static function ($signal) { - Yii::$app->end(); - }); - } - } - $ttr = $message->getProperty(self::TTR); $attempt = $message->getProperty(self::ATTEMPT, 1); @@ -349,19 +333,7 @@ public function listen() $this->redeliver($message); } - - // For amqp extension: restore default signal handlers - if ( - extension_loaded('pcntl') && function_exists('pcntl_signal') && PHP_MAJOR_VERSION >= 7 && - $this->driver === self::ENQUEUE_AMQP_EXT - ) { - pcntl_signal_dispatch(); - - $signals = [SIGTERM, SIGQUIT, SIGINT, SIGHUP]; - foreach ($signals as $signal) { - pcntl_signal($signal, SIG_DFL); - } - } + pcntl_signal_dispatch(); return true; }; From ee9b7f5571491ec1e270b583d39b47e53851b1e1 Mon Sep 17 00:00:00 2001 From: dimanzver Date: Mon, 10 Jun 2024 12:01:49 +0300 Subject: [PATCH 7/8] add job params logging --- src/cli/VerboseBehavior.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli/VerboseBehavior.php b/src/cli/VerboseBehavior.php index 4f421b383..742ab0cda 100644 --- a/src/cli/VerboseBehavior.php +++ b/src/cli/VerboseBehavior.php @@ -63,6 +63,7 @@ public function beforeExec(ExecEvent $event) $this->command->stdout($this->jobTitle($event), Console::FG_GREY); $this->command->stdout(' - ', Console::FG_YELLOW); $this->command->stdout('Started', Console::FG_GREEN); + $this->command->stdout(' (params:' . json_encode($event->job, JSON_UNESCAPED_UNICODE) . ')'); $this->command->stdout(PHP_EOL); } From b30b3ab094edc968bf1da7a14f5d4413f116a6d2 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 11 Jun 2024 18:04:40 +0300 Subject: [PATCH 8/8] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bf47f9d86..917464c6c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dimanzver/yii2-queue", + "name": "yiisoft/yii2-queue", "description": "Yii2 Queue Extension which supported DB, Redis, RabbitMQ, Beanstalk, SQS and Gearman", "type": "yii2-extension", "keywords": ["yii", "queue", "async", "gii", "db", "redis", "rabbitmq", "beanstalk", "gearman", "sqs"],