Skip to content

Commit

Permalink
Notifications #22 emailing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasar icli committed Mar 28, 2016
1 parent 44e261c commit 4c70ef7
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ aldeed:template-extension
simple:dev-error-overlay
mdg:validated-method
matteodem:easy-search@1.6.4
email
meteorhacks:ssr
15 changes: 8 additions & 7 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ accounts-password@1.1.4
adriancbo:chalk@1.0.0
alanning:roles@1.2.15
aldeed:autoform@5.8.1
aldeed:collection2@2.9.0
aldeed:collection2-core@1.1.0
aldeed:collection2@2.9.1
aldeed:collection2-core@1.1.1
aldeed:schema-deny@1.0.1
aldeed:schema-index@1.0.1
aldeed:simple-schema@1.5.3
Expand Down Expand Up @@ -95,7 +95,7 @@ less@2.5.1
livedata@1.0.15
localstorage@1.0.5
logging@1.0.8
lookback:body-class@0.4.0
lookback:body-class@0.4.1
manuel:reactivearray@1.0.5
matb33:collection-hooks@0.8.1
matteodem:easy-search@1.6.4
Expand All @@ -106,7 +106,8 @@ meteor-base@1.0.1
meteor-platform@1.2.3
meteorhacks:aggregate@1.2.1
meteorhacks:collection-utils@1.2.0
meteorhacks:inject-initial@1.0.3
meteorhacks:inject-initial@1.0.4
meteorhacks:ssr@2.2.0
meteorspark:util@0.2.0
minifiers@1.1.7
minimongo@1.0.10
Expand All @@ -122,7 +123,7 @@ npm-mongo@1.4.39_1
observe-sequence@1.0.7
ongoworks:security@1.3.0
ordered-dict@1.0.4
pmteor:dev@0.0.1
pmteor:dev@0.0.3
pmteor:dropdown@0.0.1
pmteor:freeport@0.0.1
pmteor:modal@0.0.1
Expand All @@ -147,13 +148,13 @@ routepolicy@1.0.6
service-configuration@1.0.5
session@1.1.1
sha@1.0.4
simple:dev-error-overlay@1.0.1
simple:dev-error-overlay@1.4.0
softwarerero:accounts-t9n@1.1.7
spacebars@1.0.7
spacebars-compiler@1.0.7
srp@1.0.4
standard-minifiers@1.0.2
tap:i18n@1.7.0
tap:i18n@1.8.0
templating@1.1.5
templating-tools@1.0.0
tmeasday:publish-counts@0.7.3
Expand Down
38 changes: 31 additions & 7 deletions collections/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Dev.isServer(() => {
name: this.bundleId,
script: 'main.js',
cwd: this.dir(),
autorestart: false,
env: _.extend(this.env, {
PORT: this.env.PORT || PORT,
})
Expand Down Expand Up @@ -151,6 +152,32 @@ Dev.isServer(() => {
pm2.disconnect();
});
});
},

sendEmailMembers(template, data) {
const members = Users.find({
_id: {
$in: this.memberIds
}
});

// USERS EACH
members.forEach((user) => {

// MAIL URL PARSE AND EXISTS MAIL URL
Dev.hasEnv('MAIL_URL', (MAIL_URL) => {
const { emails } = user;
const { email } = Dev.parseMailUrl(MAIL_URL);

// SEND EMAIL
Email.send({
from: email,
to: _.first(emails).address,
subject: `Pmteor - ${this.name}`,
html: SSR.render(template, data)
});
});
});
}
});

Expand All @@ -164,7 +191,7 @@ Dev.isServer(() => {
});


// REMOVE APPLICATION AFTER
// REMOVE APPLICATION AFTER
Applications.after.remove((userId, doc) => {

// Applications all logs removed.
Expand Down Expand Up @@ -193,14 +220,11 @@ Dev.isServer(() => {
});
});

Applications.before.update((userId, doc, fieldNames, modifier, options) => {
if (_.has(modifier.$set, 'status')) {
Applications.after.update((userId, doc, fieldNames, modifier, options) => {
if (_.contains(fieldNames, 'status')) {

// INSERT ERROR LOG
Logs.insert({
applicationId: doc._id,
type: modifier.$set.status
});
Logs.insert({ applicationId: doc._id, type: doc.status });
}
});
});
14 changes: 13 additions & 1 deletion collections/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@ Logs.helpers({
}
});

Dev.isServer(() => { });
Dev.isServer(() => {
Logs.after.insert((userId, doc, fieldNames, modifier, options) => {
const application = Applications.findOne(doc.applicationId);

// SEND EMAIL
if (application) {
const user = Users.findOne(userId);

// SEND EMAILS
application.sendEmailMembers('log', { user, application });
}
});
});
2 changes: 2 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ SORT_FILTERS = {
}
};

// ALLOW STATUS LIST
STATUS_ALLOWED_VALUES = ['STOP', 'EXIT', 'ONLINE', 'READY', 'ERRORED', 'RESTART', 'RESTART OVERLIMIT'];

// MAPPER STATUS LIST
STATUS_MAPPER = {
'STOP': STATUS_ALLOWED_VALUES[0],
'EXIT': STATUS_ALLOWED_VALUES[1],
Expand Down
30 changes: 30 additions & 0 deletions private/emails/log.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="20" cellspacing="0" width="600">
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="20" cellspacing="0" width="100%">
<tr>
<td align="center" valign="top">
<img width="150" src="https://raw.githubusercontent.com/pmteor/pmteor/develop/public/images/logo.png">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="20" cellspacing="0" width="100%" id="emailBody">
<tr>
<td align="center" valign="top" style="color: #505050; font-family: sans-serif; font-size: 19px;">
Application <b>{{ application.name }}</b> is {{ application.status }}
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
3 changes: 3 additions & 0 deletions server/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// EMAILS LOAD
SSR.compileTemplate('log', Assets.getText('emails/log.html'));

// COLLECTION SECURTY ARGUMENTS
PERMIT_LIST_ALL = [ 'insert', 'update', 'remove' ];

Expand Down
28 changes: 14 additions & 14 deletions server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ Meteor.startup(() => {
// PROCESS ALL EVENTS
bus.on('process:event', Meteor.bindEnvironment((query) => {
const { PORT, name } = query.process;
const application = Applications.findOne({ bundleId: name });

// SET STATUS QUERY EVENT
Applications.update({ bundleId: name }, {
$set: {
status: STATUS_MAPPER[query.event.toUpperCase()],
'env.PORT': PORT
}
});
if (application) {

// CHANGE STATUS
Applications.update({ bundleId: name }, {
$set: {
status: STATUS_MAPPER[query.event.toUpperCase()],
'env.PORT': PORT
}
});
}
}));

// IF ERROR THEN ON EVENT
Expand Down Expand Up @@ -68,14 +72,10 @@ Meteor.startup(() => {
pm2.list((err, procs) => {
const _ids = _.without(procs.map((proc) => proc.name), 'pmteor');

_.forEach(_ids, (_id) => {

// STOP APPLICATION
pm2.stop(_id, () => {
// stop list applications.
_.forEach(_ids, (_id) => pm2.stop(_id, () => {

// SUCCESS
});
});
}));
});
});
});

0 comments on commit 4c70ef7

Please sign in to comment.