Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit 491c0a9

Browse files
committed
Ajout d'un compteur de notifications
1 parent 57e8654 commit 491c0a9

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

routes/cron.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ var requestModel = require('../models/requests');
1515
exports.handleRequests = function( req, res, next ) {
1616

1717
checkSecureKey(req, res, req.params.secureKey, function() {
18+
19+
var mailNotificationCounter = 0;
20+
var pushNotificationCounter = 0;
21+
1822
requestModel.getPendingRequests(next, function( pendingRequests ) {
1923
ovh.getJson(next, function( json ) {
2024

@@ -41,6 +45,10 @@ exports.handleRequests = function( req, res, next ) {
4145

4246
availableOffers.push( offer );
4347
inform( res, request, next );
48+
mailNotificationCounter++;
49+
50+
if( request.pushbullet_token )
51+
pushNotificationCounter++;
4452

4553
}
4654

@@ -60,22 +68,47 @@ exports.handleRequests = function( req, res, next ) {
6068
for( var key in arr )
6169
availableOffers.push( arr[key] );
6270

63-
var events = [];
71+
var newRelicEvents = [];
6472

6573
async.each(availableOffers, function( availableOffer, nextOffer ) {
6674

67-
var eventObject = {
75+
var eventAvailableOffersObject = {
6876
"eventType":"availableOffers",
6977
"offer":availableOffer.offer,
7078
"zone":availableOffer.zone
7179
};
7280

73-
events.push( eventObject );
81+
newRelicEvents.push( eventAvailableOffersObject );
7482
nextOffer();
7583

7684
}, function( err ) {
7785

78-
newrelic.submitEvents( events );
86+
if( mailNotificationCounter > 0 ) {
87+
88+
var eventMailNotificationObject = {
89+
"eventType":"mailNotifications",
90+
"mailCounter":mailNotificationCounter,
91+
};
92+
93+
newRelicEvents.push( eventMailNotificationObject );
94+
95+
}
96+
97+
if( pushNotificationCounter > 0 ) {
98+
99+
var eventPushNotificationObject = {
100+
"eventType":"pushNotifications",
101+
"pushCounter":pushNotificationCounter,
102+
};
103+
104+
newRelicEvents.push( eventPushNotificationObject );
105+
106+
}
107+
108+
if( newRelicEvents.length > 0 )
109+
// Envoi des évènement à l'API de NewRelic Insights
110+
newrelic.submitEvents( newRelicEvents );
111+
79112
res.send('PROCESSING REQUESTS COMPLETED !');
80113

81114
});

routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ exports.run = function( req, res, next ) {
127127
requestModel.unique({ ref:req.body.server, mail:req.body.mail }, next, function( unique ) {
128128

129129
if( ! unique )
130-
callback("Votre demande est toujours en attente, vous ne pouvez pas en créer plusieurs à la fois. Merci d'attendre de recevoir la notification par mail / SMS.");
130+
callback("Votre demande est toujours en attente, vous ne pouvez pas en créer plusieurs à la fois. Merci d'attendre de recevoir la notification par mail / Pushbullet.");
131131
else
132132
callback();
133133

0 commit comments

Comments
 (0)