Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MailQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ 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.');
}

$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'];
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

```
Expand All @@ -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

```

Expand Down
4 changes: 2 additions & 2 deletions commands/MailQueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}