Skip to content

Commit

Permalink
No longer queue notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Rias committed May 21, 2018
1 parent c26cc37 commit 653c94c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 88 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.1.0 - 2018-05-21
### Changed
- Notifications are no longer queued as this causes a lot of issues with serialization. Will find a better solution for this in the future.

## 1.0.6 - 2018-03-06
### Added
- Notification now extends the Craft base model for easier configuration
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rias/craft-notifications",
"description": "Send notifications across a variety of delivery channels, including mail and Slack. Notifications may also be stored in a database so they may be displayed in your web interface.",
"type": "craft-plugin",
"version": "1.0.6",
"version": "1.1.0",
"keywords": [
"craft",
"cms",
Expand Down
23 changes: 5 additions & 18 deletions src/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use craft\console\Application as ConsoleApplication;
use craft\web\twig\variables\CraftVariable;
use yii\base\Event;
use yii\queue\serializers\PhpSerializer;

/**
* Craft plugins are very much like little applications in and of themselves. We’ve made
Expand Down Expand Up @@ -91,24 +90,12 @@ function (Event $event) {
$notificationSettings['class'],
$notificationSettings['event'],
function (Event $event) use ($notificationSettings) {
try {
// Make sure the event can be serialized
$serializer = new PhpSerializer();
$serializer->serialize($event);
/* @var Notification $notification */
$notification = $notificationSettings['notification'];

// Create a queue job to send the notification if the notification should be queued
Craft::$app->queue->push(new SendNotification([
'notificationSettings' => $notificationSettings,
'event' => $event,
]));
} catch (\Exception $e) { // Don't queue the notification if it cannot be serialized
/* @var Notification $notification */
$notification = $notificationSettings['notification'];

Notifications::$plugin->notificationsService->send(
new $notification(['event' => $event])
);
}
Notifications::$plugin->notificationsService->send(
new $notification(['event' => $event])
);
}
);
}
Expand Down
69 changes: 0 additions & 69 deletions src/jobs/SendNotification.php

This file was deleted.

0 comments on commit 653c94c

Please sign in to comment.