Permalink
Browse files

Packaging for deploy

  • Loading branch information...
1 parent 150247e commit 7afd5d22c1d44b93c7cb2250ea9e05ef7b8451f8 Loren West committed May 16, 2014
Showing with 164 additions and 31 deletions.
  1. +5 −0 History.md
  2. +77 −13 dist/monitor-all.js
  3. +2 −2 dist/monitor-all.min.js
  4. +77 −13 dist/monitor.js
  5. +2 −2 dist/monitor.min.js
  6. +1 −1 package.json
View
@@ -1,3 +1,8 @@
+0.6.10 / 2014-05-16
+===================
+
+ * Added cron/interval polling to RecipeProbe
+
0.6.9 / 2014-03-26
===================
View
@@ -1,4 +1,4 @@
-/* monitor - v0.6.9 - 2014-03-26 */
+/* monitor - v0.6.10 - 2014-05-16 */
// Underscore.js 1.4.4
// http://underscorejs.org
@@ -10554,9 +10554,10 @@ if (typeof define === "function" && define.amd) {
// Module loading - this runs server-side only
var Monitor = root.Monitor || require('../Monitor'),
+ _ = Monitor._,
+ Cron = Monitor.Cron,
logger = Monitor.getLogger('RecipeProbe'),
vm = Monitor.commonJS ? require('vm') : null,
- _ = Monitor._,
Probe = Monitor.Probe;
/**
@@ -10585,6 +10586,18 @@ if (typeof define === "function" && define.amd) {
* monitors by name.
* @param [recipeName] {String} - Recipe name for logging
* @param [autoStart=false] {boolean} - Call the start control on instantiation?
+ * @param [triggeredBy] {Object} - Trigger the recipe by the items in the object.
+ * Items can include: 'interval', 'cron', and/or monitorName(s)
+ * If 'interval' is the key, the value is the interval in milliseconds
+ * If 'cron' is the key, the value is a string representing the cron pattern
+ * If any monitor name is the key, the value is the monitor event to trigger on.
+ * Example:
+ * triggeredBy: {
+ * interval: 5000, // This triggers the recipe every 5 seconds
+ * cron: '* * * * * *', // [second] [minute] [hour] [day of month] [month] [day of week]
+ * myMonitor: 'change:someAttribute change:someOtherAttribute'
+ * }
+ * If triggeredBy isn't specified, any monitor change will trigger the recipe.
* @param [started] {boolean} - Is the recipe started and currently active?
*/
var RecipeProbe = Monitor.RecipeProbe = Probe.extend({
@@ -10596,12 +10609,17 @@ if (typeof define === "function" && define.amd) {
monitors: {},
script: '',
autoStart: false,
- started: false
+ started: false,
+ triggeredBy: null
},
initialize: function(attributes, options){
var t = this;
+ // Periodic triggers
+ t.interval = null;
+ t.cronJob = null;
+
// Precondition test
if (_.size(t.get('monitors')) === 0) {
logger.error('initialize', 'No monitors defined in the recipe');
@@ -10629,7 +10647,7 @@ if (typeof define === "function" && define.amd) {
/**
* Start the recipe
*
- * This connects to each monitor and watches for change events
+ * This connects to each monitor and sets up the recipe triggers
*
* @method start_control
*/
@@ -10722,23 +10740,66 @@ if (typeof define === "function" && define.amd) {
* @method connectListeners
*/
connectListeners: function(connect) {
- var t = this;
- for (var monitorName in t.monitors) {
- t.monitors[monitorName][connect ? 'on' : 'off']('change', t.onChange, t);
+ var t = this,
+ triggeredBy = t.get('triggeredBy'),
+ onTrigger = t.onTrigger.bind(t);
+
+ // Default to listen on changes to all monitors
+ if (!triggeredBy) {
+ for (var monitorName in t.monitors) {
+ t.monitors[monitorName][connect ? 'on' : 'off']('change', t.onTrigger, t);
+ }
+ return;
+ }
+
+ // Process the elements in triggeredBy
+ for (var name in triggeredBy) {
+ var value = triggeredBy[name];
+
+ // Construct a new cron job
+ if (name === 'cron') {
+ if (connect) {
+ t.cronJob = new Cron.CronJob(value, onTrigger);
+ }
+ else {
+ if (t.cronJob.initiated) {
+ clearInterval(t.CronJob.timer);
+ }
+ else {
+ setTimeout(function(){clearInterval(t.cronJob.timer);}, 1000);
+ }
+ }
+ }
+
+ // Set a polling interval
+ else if (name === 'interval') {
+ if (connect) {
+ t.interval = setInterval(onTrigger, value);
+ }
+ else {
+ clearInterval(t.interval);
+ t.interval = null;
+ }
+ }
+
+ // Must be a monitor name
+ else {
+ t.monitors[name][connect ? 'on' : 'off'](value, onTrigger);
+ }
}
},
/**
- * Called when a change is detected
+ * Called when a trigger is fired
*
* @private
- * @method onChange
+ * @method onTrigger
*/
- onChange: function() {
+ onTrigger: function() {
var t = this;
t.run_control({}, function(error){
if (error) {
- logger.error('onChange', error);
+ logger.error('onTrigger', error);
}
});
},
@@ -10840,8 +10901,11 @@ if (typeof define === "function" && define.amd) {
(function(root){
// Module loading
- var Monitor = root.Monitor || require('../Monitor'), Probe = Monitor.Probe,
- Cron = Monitor.Cron, _ = Monitor._, Backbone = Monitor.Backbone;
+ var Monitor = root.Monitor || require('../Monitor'),
+ _ = Monitor._,
+ Cron = Monitor.Cron,
+ Probe = Monitor.Probe,
+ Backbone = Monitor.Backbone;
// Constants
var DEFAULT_POLL_INTERVAL = 1000;
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,4 +1,4 @@
-/* monitor - v0.6.9 - 2014-03-26 */
+/* monitor - v0.6.10 - 2014-05-16 */
// Monitor.js (c) 2010-2014 Loren West and other contributors
// May be freely distributed under the MIT license.
@@ -3809,9 +3809,10 @@
// Module loading - this runs server-side only
var Monitor = root.Monitor || require('../Monitor'),
+ _ = Monitor._,
+ Cron = Monitor.Cron,
logger = Monitor.getLogger('RecipeProbe'),
vm = Monitor.commonJS ? require('vm') : null,
- _ = Monitor._,
Probe = Monitor.Probe;
/**
@@ -3840,6 +3841,18 @@
* monitors by name.
* @param [recipeName] {String} - Recipe name for logging
* @param [autoStart=false] {boolean} - Call the start control on instantiation?
+ * @param [triggeredBy] {Object} - Trigger the recipe by the items in the object.
+ * Items can include: 'interval', 'cron', and/or monitorName(s)
+ * If 'interval' is the key, the value is the interval in milliseconds
+ * If 'cron' is the key, the value is a string representing the cron pattern
+ * If any monitor name is the key, the value is the monitor event to trigger on.
+ * Example:
+ * triggeredBy: {
+ * interval: 5000, // This triggers the recipe every 5 seconds
+ * cron: '* * * * * *', // [second] [minute] [hour] [day of month] [month] [day of week]
+ * myMonitor: 'change:someAttribute change:someOtherAttribute'
+ * }
+ * If triggeredBy isn't specified, any monitor change will trigger the recipe.
* @param [started] {boolean} - Is the recipe started and currently active?
*/
var RecipeProbe = Monitor.RecipeProbe = Probe.extend({
@@ -3851,12 +3864,17 @@
monitors: {},
script: '',
autoStart: false,
- started: false
+ started: false,
+ triggeredBy: null
},
initialize: function(attributes, options){
var t = this;
+ // Periodic triggers
+ t.interval = null;
+ t.cronJob = null;
+
// Precondition test
if (_.size(t.get('monitors')) === 0) {
logger.error('initialize', 'No monitors defined in the recipe');
@@ -3884,7 +3902,7 @@
/**
* Start the recipe
*
- * This connects to each monitor and watches for change events
+ * This connects to each monitor and sets up the recipe triggers
*
* @method start_control
*/
@@ -3977,23 +3995,66 @@
* @method connectListeners
*/
connectListeners: function(connect) {
- var t = this;
- for (var monitorName in t.monitors) {
- t.monitors[monitorName][connect ? 'on' : 'off']('change', t.onChange, t);
+ var t = this,
+ triggeredBy = t.get('triggeredBy'),
+ onTrigger = t.onTrigger.bind(t);
+
+ // Default to listen on changes to all monitors
+ if (!triggeredBy) {
+ for (var monitorName in t.monitors) {
+ t.monitors[monitorName][connect ? 'on' : 'off']('change', t.onTrigger, t);
+ }
+ return;
+ }
+
+ // Process the elements in triggeredBy
+ for (var name in triggeredBy) {
+ var value = triggeredBy[name];
+
+ // Construct a new cron job
+ if (name === 'cron') {
+ if (connect) {
+ t.cronJob = new Cron.CronJob(value, onTrigger);
+ }
+ else {
+ if (t.cronJob.initiated) {
+ clearInterval(t.CronJob.timer);
+ }
+ else {
+ setTimeout(function(){clearInterval(t.cronJob.timer);}, 1000);
+ }
+ }
+ }
+
+ // Set a polling interval
+ else if (name === 'interval') {
+ if (connect) {
+ t.interval = setInterval(onTrigger, value);
+ }
+ else {
+ clearInterval(t.interval);
+ t.interval = null;
+ }
+ }
+
+ // Must be a monitor name
+ else {
+ t.monitors[name][connect ? 'on' : 'off'](value, onTrigger);
+ }
}
},
/**
- * Called when a change is detected
+ * Called when a trigger is fired
*
* @private
- * @method onChange
+ * @method onTrigger
*/
- onChange: function() {
+ onTrigger: function() {
var t = this;
t.run_control({}, function(error){
if (error) {
- logger.error('onChange', error);
+ logger.error('onTrigger', error);
}
});
},
@@ -4095,8 +4156,11 @@
(function(root){
// Module loading
- var Monitor = root.Monitor || require('../Monitor'), Probe = Monitor.Probe,
- Cron = Monitor.Cron, _ = Monitor._, Backbone = Monitor.Backbone;
+ var Monitor = root.Monitor || require('../Monitor'),
+ _ = Monitor._,
+ Cron = Monitor.Cron,
+ Probe = Monitor.Probe,
+ Backbone = Monitor.Backbone;
// Constants
var DEFAULT_POLL_INTERVAL = 1000;
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
{
"name": "monitor",
"description": "Runtime monitoring for node.js applications",
- "version": "0.6.9",
+ "version": "0.6.10",
"main": "./lib/index.js",
"author": {
"name": "Loren West",

0 comments on commit 7afd5d2

Please sign in to comment.