Skip to content

Commit

Permalink
Merge tag '4.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jprodrigues70 committed Jan 26, 2021
2 parents ff0ba07 + 912d0d0 commit 4f24821
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ When you are in a dev environment (i.e. using the `.test` domain with Valet, or

## Events

When an email is sent, viewed, or a link is clicked, its tracking information is counted in the database using the jdavidbakr\MailTracker\Model\SentEmail model. This processing is done via dispatched jobs to the default queue in order to prevent the database from being overwhelmed is an email blast situation.
When an email is sent, viewed, or a link is clicked, its tracking information is counted in the database using the jdavidbakr\MailTracker\Model\SentEmail model. This processing is done via dispatched jobs to the queue in order to prevent the database from being overwhelmed in an email blast situation. You may choose the queue that these events are dispatched via the `mail-tracker.tracker-queue` config setting, or leave it `null` to use the default queue.

You may want to do additional processing on these events, so an event is fired in these cases:

Expand Down
7 changes: 6 additions & 1 deletion config/mail-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
/**
* Determines whether or not the body of the email is logged in the sent_emails table
*/
'log-content' => true
'log-content' => true,

/**
* What queue should we dispatch our tracking jobs to? Null will use the default queue.
*/
'tracker-queue' => null,

];
6 changes: 4 additions & 2 deletions src/MailTrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function getT($hash)
$tracker = Model\SentEmail::where('hash', $hash)
->first();
if ($tracker) {
RecordTrackingJob::dispatch($tracker);
RecordTrackingJob::dispatch($tracker)
->onQueue(config('mail-tracker.tracker-queue'));
}

return $response;
Expand All @@ -58,7 +59,8 @@ protected function linkClicked($url, $hash)
$tracker = Model\SentEmail::where('hash', $hash)
->first();
if ($tracker) {
RecordLinkClickJob::dispatch($tracker, $url);
RecordLinkClickJob::dispatch($tracker, $url)
->onQueue(config('mail-tracker.tracker-queue'));
return redirect($url);
}

Expand Down
9 changes: 6 additions & 3 deletions src/SNSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,19 @@ protected function process_notification($message)

protected function process_delivery($message)
{
RecordDeliveryJob::dispatch($message);
RecordDeliveryJob::dispatch($message)
->onQueue(config('mail-tracker.tracker-queue'));
}

public function process_bounce($message)
{
RecordBounceJob::dispatch($message);
RecordBounceJob::dispatch($message)
->onQueue(config('mail-tracker.tracker-queue'));
}

public function process_complaint($message)
{
RecordComplaintJob::dispatch($message);
RecordComplaintJob::dispatch($message)
->onQueue(config('mail-tracker.tracker-queue'));
}
}
26 changes: 18 additions & 8 deletions tests/MailTrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public function it_doesnt_track_if_told_not_to()
*/
public function testPing()
{
Config::set('mail-tracker.tracker-queue', 'alt-queue');
Bus::fake();
$track = \jdavidbakr\MailTracker\Model\SentEmail::create([
'hash' => Str::random(32),
Expand All @@ -204,12 +205,14 @@ public function testPing()

$response->assertSuccessful();
Bus::assertDispatched(RecordTrackingJob::class, function ($e) use ($track) {
return $e->sentEmail->id == $track->id;
return $e->sentEmail->id == $track->id &&
$e->queue == 'alt-queue';
});
}

public function testLegacyLink()
{
Config::set('mail-tracker.tracker-queue', 'alt-queue');
Bus::fake();
$track = \jdavidbakr\MailTracker\Model\SentEmail::create([
'hash' => Str::random(32),
Expand All @@ -226,12 +229,14 @@ public function testLegacyLink()
$response->assertRedirect($redirect);
Bus::assertDispatched(RecordLinkClickJob::class, function ($job) use ($track, $redirect) {
return $job->sentEmail->id == $track->id &&
$job->url == $redirect;
$job->url == $redirect &&
$job->queue == 'alt-queue';
});
}

public function testLink()
{
Config::set('mail-tracker.tracker-queue', 'alt-queue');
Bus::fake();
$track = \jdavidbakr\MailTracker\Model\SentEmail::create([
'hash' => Str::random(32),
Expand All @@ -247,7 +252,8 @@ public function testLink()
$response->assertRedirect($redirect);
Bus::assertDispatched(RecordLinkClickJob::class, function ($job) use ($track, $redirect) {
return $job->sentEmail->id == $track->id &&
$job->url == $redirect;
$job->url == $redirect &&
$job->queue == 'alt-queue';
});
}

Expand Down Expand Up @@ -516,7 +522,7 @@ public function it_ignores_invalid_topic()
*/
public function it_processes_a_delivery()
{
$this->disableExceptionHandling();
Config::set('mail-tracker.tracker-queue', 'alt-queue');
Bus::fake();
$message = [
'notificationType' => 'Delivery',
Expand All @@ -537,7 +543,8 @@ public function it_processes_a_delivery()

$response->assertSee('notification processed');
Bus::assertDispatched(RecordDeliveryJob::class, function ($job) use ($message) {
return $job->message == (object)$message;
return $job->message == (object)$message &&
$job->queue == 'alt-queue';
});
}

Expand All @@ -546,6 +553,7 @@ public function it_processes_a_delivery()
*/
public function it_processes_a_bounce()
{
Config::set('mail-tracker.tracker-queue', 'alt-queue');
Bus::fake();
$message = [
'notificationType' => 'Bounce',
Expand All @@ -566,7 +574,8 @@ public function it_processes_a_bounce()

$response->assertSee('notification processed');
Bus::assertDispatched(RecordBounceJob::class, function ($job) use ($message) {
return $job->message == (object)$message;
return $job->message == (object)$message &&
$job->queue == 'alt-queue';
});
}

Expand All @@ -575,7 +584,7 @@ public function it_processes_a_bounce()
*/
public function it_processes_a_complaint()
{
$this->disableExceptionHandling();
Config::set('mail-tracker.tracker-queue', 'alt-queue');
Bus::fake();
$message = [
'notificationType' => 'Complaint',
Expand All @@ -596,7 +605,8 @@ public function it_processes_a_complaint()

$response->assertSee('notification processed');
Bus::assertDispatched(RecordComplaintJob::class, function ($job) use ($message) {
return $job->message == (object)$message;
return $job->message == (object)$message &&
$job->queue == 'alt-queue';
});
}

Expand Down

0 comments on commit 4f24821

Please sign in to comment.