Created
December 6, 2017 20:10
-
-
Save steve-ross/b719f56a133d4c376c598637b9f2b48f to your computer and use it in GitHub Desktop.
Validated alert method for meteor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// location: imports/api/util/server/methods.js | |
import { Meteor } from 'meteor/meteor'; | |
import { ValidatedMethod } from 'meteor/mdg:validated-method'; | |
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | |
const env = process.env.NODE_ENV; | |
const environmentInfo = env === 'development' ? `[${process.env.HOME}]` : `${Meteor.settings['galaxy.meteor.com'].env.ROOT_URL}`; | |
const alert = new ValidatedMethod({ | |
name: 'util.alert' | |
, validate: new SimpleSchema({ | |
text: { type: String }, | |
type: { | |
type: String, | |
allowedValues: ['alert', 'note', 'success', 'bug'], | |
optional: true | |
} | |
}).validator() | |
, run({ text, type }) { | |
// TODO: add security and move out of server folder | |
const alertType = type || 'alert'; // validator doesn't seem to mutate the object (set the default alert type manually) | |
const doAlert = env === 'development' ? console.error : slack[alertType]; | |
doAlert(`${environmentInfo} ${text}`); | |
} | |
}); | |
export default alert; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// location: /server/startup/migrations/migrations.js | |
import alert from '../../../imports/api/util/server/methods'; | |
Meteor.startup(() => { | |
const status = Migrations._getControl(); | |
// defaults to migraion failed, and the lock was not cleared before re-starting the app | |
const message = { text: `ERROR: Migration STILL LOCKED at ${status.version}` }; | |
if (!status.locked) { | |
Migrations.migrateTo('latest'); | |
const newStatus = Migrations._getControl(); | |
if (newStatus.locked) { | |
message.text = `ERROR: Migration FAILURE check the logs! (locked at ${newStatus.version})`; | |
} else if (status.version < newStatus.version) { | |
// migration actually ran, alert version changes | |
message.text = `Started & Migrated from ${status.version} to ${newStatus.version}`; | |
message.type = 'success'; | |
} else { | |
message.text = 'Started'; | |
message.type = 'success'; | |
} | |
} | |
alert.call(message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment