From 8c9e2fc9676f892ad1fce1fe7b472592d79a3aaf Mon Sep 17 00:00:00 2001 From: andrey82k Date: Mon, 20 Feb 2017 21:58:54 +0300 Subject: [PATCH 1/3] Update MailQueueController.php --- commands/MailQueueController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/MailQueueController.php b/commands/MailQueueController.php index 93c8681..329b6d5 100644 --- a/commands/MailQueueController.php +++ b/commands/MailQueueController.php @@ -24,8 +24,8 @@ class MailQueueController extends Controller /** * This command processes the mail queue */ - public function actionProcess() + public function actionProcess($qty = null) { - \Yii::$app->mailqueue->process(); + \Yii::$app->mailqueue->process($qty); } } From 7d628c92401a5dfd9be79c3dc6908ee45abfa598 Mon Sep 17 00:00:00 2001 From: andrey82k Date: Mon, 20 Feb 2017 22:01:17 +0300 Subject: [PATCH 2/3] Update MailQueue.php --- MailQueue.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MailQueue.php b/MailQueue.php index 4069fe3..ae89eb8 100644 --- a/MailQueue.php +++ b/MailQueue.php @@ -81,9 +81,10 @@ public function init() /** * Sends out the messages in email queue and update the database. * + * @param int $qty the number of mails to be sent * @return boolean true if all messages are successfully sent out */ - public function process() + public function process($qty = null) { if (Yii::$app->db->getTableSchema($this->table) == null) { throw new \yii\base\InvalidConfigException('"' . $this->table . '" not found in database. Make sure the db migration is properly done and the table is created.'); @@ -91,7 +92,7 @@ public function process() $success = true; - $items = Queue::find()->where(['and', ['sent_time' => NULL], ['<', 'attempts', $this->maxAttempts], ['<=', 'time_to_send', date('Y-m-d H:i:s')]])->orderBy(['created_at' => SORT_ASC])->limit($this->mailsPerRound); + $items = Queue::find()->where(['and', ['sent_time' => NULL], ['<', 'attempts', $this->maxAttempts], ['<=', 'time_to_send', date('Y-m-d H:i:s')]])->orderBy(['created_at' => SORT_ASC])->limit($qty ?: $this->mailsPerRound); foreach ($items->each() as $item) { if ($message = $item->toMessage()) { $attributes = ['attempts', 'last_attempt_time']; From 6a6a1c19f19de73c3fa69044c7a7ffc9df3932b5 Mon Sep 17 00:00:00 2001 From: andrey82k Date: Wed, 22 Feb 2017 12:49:01 +0300 Subject: [PATCH 3/3] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e74aa6a..f1524fa 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ In one of your controller actions: ```php -public function actionSend() +public function actionSend($qty = null) { - Yii::$app->mailqueue->process(); + Yii::$app->mailqueue->process($qty); } ``` @@ -98,7 +98,7 @@ Set a CRON job to run console command: ``` -*/10 * * * * php /var/www/html/myapp/yii mailqueue/process +*/10 * * * * php /var/www/html/myapp/yii mailqueue/process 25 ```