Skip to content

Commit 09c8a99

Browse files
committed
README update and added timeout option
1 parent a69c4ed commit 09c8a99

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This is a package that stores and queues e-mails using a database table. Easily
2525
- [Resend failed e-mails](#resend-failed-e-mails)
2626
- [Encryption (optional)](#encryption-optional)
2727
- [Test mode (optional)](#test-mode-optional)
28+
- [E-mails to send per minute](#e-mails-to-send-per-minute)
2829

2930
### Installation
3031

@@ -63,10 +64,12 @@ Now add the e-mail cronjob to your scheduler.
6364
*/
6465
protected function schedule(Schedule $schedule)
6566
{
66-
$schedule->command('email:send')->everyMinute()->withoutOverlapping(5);
67+
$schedule->command('email:send', ['--timeout' => 300])->everyMinute()->withoutOverlapping(5);
6768
}
6869
```
6970

71+
Using the above configuration, the `email:send` process will exit after 5 minutes (`--timeout`) and won't overlap if the process still runs after 5 minutes (`withoutOverlapping`)
72+
7073
### Usage
7174

7275
#### Send an email
@@ -195,4 +198,8 @@ With encryption the table size is ± 50.58 MB.
195198

196199
#### Test mode (Optional)
197200

198-
When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.
201+
When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.
202+
203+
#### E-mails to send per minute
204+
205+
To configure how many e-mails should be sent each command, please check the `limit` option. The default is `20` e-mails every command.

src/SendEmailsCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SendEmailsCommand extends Command
1313
*
1414
* @var string
1515
*/
16-
protected $signature = 'email:send';
16+
protected $signature = 'email:send {--timeout=300}';
1717

1818
/**
1919
* The console command description.
@@ -48,6 +48,8 @@ public function __construct(Store $store)
4848
*/
4949
public function handle()
5050
{
51+
set_time_limit($this->option('timeout'));
52+
5153
$emails = $this->store->getQueue();
5254

5355
if ($emails->isEmpty()) {
@@ -70,6 +72,8 @@ public function handle()
7072
$progress->finish();
7173

7274
$this->result($emails);
75+
76+
set_time_limit(0);
7377
}
7478

7579
/**

tests/SendEmailsCommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,18 @@ function the_failed_status_and_error_is_cleared_if_a_previously_failed_email_is_
123123
$this->assertFalse($email->fresh()->hasFailed());
124124
$this->assertEmpty($email->fresh()->getError());
125125
}
126+
127+
/** @test */
128+
function the_command_will_be_stopped_after_the_timeout()
129+
{
130+
$this->assertEquals(0, ini_get('max_execution_time'));
131+
132+
$this->artisan('email:send');
133+
134+
$this->assertEquals(300, ini_get('max_execution_time'));
135+
136+
$this->artisan('email:send', ['--timeout' => 60]);
137+
138+
$this->assertEquals(60, ini_get('max_execution_time'));
139+
}
126140
}

0 commit comments

Comments
 (0)