mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-04-05 15:41:00 +00:00
Start time added to event poller
This commit is contained in:
parent
d31e66a701
commit
4cd014801a
10 changed files with 124 additions and 32 deletions
|
|
@ -225,6 +225,7 @@ storeRule = ( user, oPayload, callback ) =>
|
|||
rule =
|
||||
id: oPayload.id
|
||||
event: oPayload.event
|
||||
event_start: oPayload.event_start
|
||||
event_interval: oPayload.event_interval
|
||||
conditions: oPayload.conditions
|
||||
actions: oPayload.actions
|
||||
|
|
|
|||
|
|
@ -106,11 +106,22 @@ fLoadModule = ( msg ) ->
|
|||
timestamp: ts
|
||||
oUser[msg.rule.id].module.pushEvent = fPushEvent msg.user, msg.rule.id, oUser[msg.rule.id]
|
||||
|
||||
|
||||
start = new Date msg.rule.event_start
|
||||
nd = new Date()
|
||||
if start < nd
|
||||
# If the engine restarts start could be from last year even
|
||||
start.setYear nd.getYear()
|
||||
start.setMonth nd.getMonth()
|
||||
start.setDate nd.getDate()
|
||||
# if it's still smaller we add one day
|
||||
if start < nd
|
||||
start.setDate nd.getDate() + 1
|
||||
|
||||
log.info "EP | New event module '#{ arrName[0] }' loaded for user #{ msg.user },
|
||||
in rule #{ msg.rule.id }, starting at UTC|#{ ts.toISOString() }
|
||||
in rule #{ msg.rule.id }, registered at UTC|#{ ts.toISOString() },
|
||||
starting at UTC|#{ start.toISOString() } ( which is in #{ ( start - nd ) / 1000 / 60 } minutes )
|
||||
and polling every #{ msg.rule.event_interval } minutes"
|
||||
setTimeout fCheckAndRun( msg.user, msg.rule.id, ts ), 1000
|
||||
setTimeout fCheckAndRun( msg.user, msg.rule.id, ts ), start - nd
|
||||
|
||||
if msg.event is 'new' or
|
||||
not listUserModules[msg.user] or
|
||||
|
|
|
|||
|
|
@ -74,13 +74,7 @@ exports = module.exports = ( args ) =>
|
|||
if err
|
||||
@log.error "RH | Unable to write new user file! "
|
||||
@log.error err
|
||||
# {
|
||||
# "admin": {
|
||||
# "password": "7407946a7a90b037ba5e825040f184a142161e4c61d81feb83ec8c7f011a99b0d77f39c9170c3231e1003c5cf859c69bd93043b095feff5cce6f6d45ec513764",
|
||||
# "roles": ["admin"]
|
||||
# }
|
||||
# }
|
||||
# {"admin":{"password":"7407946a7a90b037ba5e825040f184a142161e4c61d81feb83ec8c7f011a99b0d77f39c9170c3231e1003c5cf859c69bd93043b095feff5cce6f6d45ec513764","roles":["admin"]},"dominic":{"password":"2d51496fbe5b6d3e98e22d68140609eaedd64de457b2f75c346a4a98f87928eac11ea2be747709ae7a2f5b177af09a60a8dbf14bf703e0cb9b147fc0a3e3a064","roles":[]}}
|
||||
|
||||
fs.readFile pathUsers, 'utf8', fPersistNewUser obj.username, obj.password, roles
|
||||
else
|
||||
data.code = 401
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"http-port": 8125,
|
||||
"db-port": 6379,
|
||||
"db-select": 0,
|
||||
"db-select": 1,
|
||||
"log": {
|
||||
"nolog": "false",
|
||||
"mode": "productive",
|
||||
|
|
|
|||
|
|
@ -314,6 +314,7 @@ Components Manager
|
|||
rule = {
|
||||
id: oPayload.id,
|
||||
event: oPayload.event,
|
||||
event_start: oPayload.event_start,
|
||||
event_interval: oPayload.event_interval,
|
||||
conditions: oPayload.conditions,
|
||||
actions: oPayload.actions
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ Dynamic Modules
|
|||
return log.warn("EP | Strange... no module retrieved: " + arrName[0]);
|
||||
} else {
|
||||
return dynmod.compileString(obj.data, msg.user, msg.rule.id, arrName[0], obj.lang, db.eventPollers, function(result) {
|
||||
var oUser, ts;
|
||||
var nd, oUser, start, ts;
|
||||
if (!result.answ === 200) {
|
||||
log.error("EP | Compilation of code failed! " + msg.user + ", " + msg.rule.id + ", " + arrName[0]);
|
||||
}
|
||||
|
|
@ -103,8 +103,18 @@ Dynamic Modules
|
|||
timestamp: ts
|
||||
};
|
||||
oUser[msg.rule.id].module.pushEvent = fPushEvent(msg.user, msg.rule.id, oUser[msg.rule.id]);
|
||||
log.info("EP | New event module '" + arrName[0] + "' loaded for user " + msg.user + ", in rule " + msg.rule.id + ", starting at UTC|" + (ts.toISOString()) + " and polling every " + msg.rule.event_interval + " minutes");
|
||||
return setTimeout(fCheckAndRun(msg.user, msg.rule.id, ts), 1000);
|
||||
start = new Date(msg.rule.event_start);
|
||||
nd = new Date();
|
||||
if (start < nd) {
|
||||
start.setYear(nd.getYear());
|
||||
start.setMonth(nd.getMonth());
|
||||
start.setDate(nd.getDate());
|
||||
if (start < nd) {
|
||||
start.setDate(nd.getDate() + 1);
|
||||
}
|
||||
}
|
||||
log.info("EP | New event module '" + arrName[0] + "' loaded for user " + msg.user + ", in rule " + msg.rule.id + ", registered at UTC|" + (ts.toISOString()) + ", starting at UTC|" + (start.toISOString()) + " ( which is in " + ((start - nd) / 1000 / 60) + " minutes ) and polling every " + msg.rule.event_interval + " minutes");
|
||||
return setTimeout(fCheckAndRun(msg.user, msg.rule.id, ts), start - nd);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,8 +10,11 @@ if oParams.id
|
|||
|
||||
strPublicKey = ''
|
||||
fPlaceAndPaintInterval = () ->
|
||||
$( '#input_interval' ).html 'Interval:
|
||||
<input id="event_interval" type="text" />
|
||||
$( '#event_start' ).html 'Start Time:
|
||||
<input id="input_start" type="text" />
|
||||
<b>"hh:mm"</b>, default = 12:00'
|
||||
$( '#event_interval' ).html 'Interval:
|
||||
<input id="input_interval" type="text" />
|
||||
<b>"days hours:minutes"</b>, default = 10 minutes'
|
||||
|
||||
fFailedRequest = ( msg ) ->
|
||||
|
|
@ -63,7 +66,8 @@ fOnLoad = () ->
|
|||
$( '#select_event' ).change () ->
|
||||
evtFunc = $( this ).val()
|
||||
if evtFunc is ''
|
||||
$( '#input_interval' ).html ''
|
||||
$( '#event_start' ).html ''
|
||||
$( '#event_interval' ).html ''
|
||||
else
|
||||
fPlaceAndPaintInterval()
|
||||
$( '#input_event' ).val evtFunc
|
||||
|
|
@ -74,7 +78,8 @@ fOnLoad = () ->
|
|||
$( '#select_event' ).val $( this ).val()
|
||||
fFetchEventParams $( '#select_event' ).val()
|
||||
if $( '#select_event' ).val() is ''
|
||||
$( '#input_interval' ).html ''
|
||||
$( '#event_start' ).html ''
|
||||
$( '#event_interval' ).html ''
|
||||
else
|
||||
fPlaceAndPaintInterval()
|
||||
|
||||
|
|
@ -418,6 +423,34 @@ fOnLoad = () ->
|
|||
if conds not instanceof Array
|
||||
throw new Error "Conditions Invalid! Needs to be an Array of Strings!"
|
||||
|
||||
|
||||
txtStart = $( '#input_start' ).val()
|
||||
start = new Date()
|
||||
if not txtStart
|
||||
start.setHours 12
|
||||
start.setMinutes 0
|
||||
console.log 'setting to 12:00: ' + start.toString()
|
||||
else
|
||||
arrInp = txtStart.split ':'
|
||||
# There's only one string entered: hour
|
||||
if arrInp.length is 1
|
||||
txtHr = txtStart
|
||||
start.setMinutes 0
|
||||
else
|
||||
txtHr = arrInp[ 0 ]
|
||||
intMin = parseInt( arrInp[ 1 ] ) || 0
|
||||
m = Math.max 0, Math.min intMin, 59
|
||||
start.setMinutes m
|
||||
|
||||
intHour = parseInt( txtHr ) || 12
|
||||
h = Math.max 0, Math.min intHour, 12
|
||||
start.setHours h
|
||||
|
||||
start.setSeconds 0
|
||||
start.setMilliseconds 0
|
||||
if start < new Date()
|
||||
start.setDate start.getDate() + 1
|
||||
|
||||
# Parse a time string
|
||||
fParseTime = ( str, hasDay ) ->
|
||||
arrTime = str.split ':'
|
||||
|
|
@ -438,8 +471,7 @@ fOnLoad = () ->
|
|||
def = 0
|
||||
h * 60 + ( parseInt( arrTime[ 1 ] ) || def )
|
||||
|
||||
|
||||
txtInterval = $( '#event_interval' ).val()
|
||||
txtInterval = $( '#input_interval' ).val()
|
||||
if not txtInterval
|
||||
mins = 10
|
||||
else
|
||||
|
|
@ -475,6 +507,7 @@ fOnLoad = () ->
|
|||
id: $( '#input_id' ).val()
|
||||
event: eventId
|
||||
event_params: ep
|
||||
event_start: start.toISOString()
|
||||
event_interval: mins
|
||||
event_functions: evtFuncs
|
||||
conditions: conds
|
||||
|
|
@ -511,7 +544,12 @@ fOnLoad = () ->
|
|||
fPlaceAndPaintInterval()
|
||||
|
||||
$( '#input_event' ).val oRule.event
|
||||
$( '#event_interval' ).val oRule.event_interval
|
||||
d = new Date oRule.event_start
|
||||
mins = d.getMinutes()
|
||||
if mins.toString().length is 1
|
||||
mins = '0' + mins
|
||||
$( '#input_start' ).val d.getHours() + ':' + mins
|
||||
$( '#input_interval' ).val oRule.event_interval
|
||||
|
||||
# Conditions
|
||||
editor.setValue JSON.stringify oRule.conditions, undefined, 2
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
strPublicKey = '';
|
||||
|
||||
fPlaceAndPaintInterval = function() {
|
||||
return $('#input_interval').html('Interval: <input id="event_interval" type="text" /> <b>"days hours:minutes"</b>, default = 10 minutes');
|
||||
$('#event_start').html('Start Time: <input id="input_start" type="text" /> <b>"hh:mm"</b>, default = 12:00');
|
||||
return $('#event_interval').html('Interval: <input id="input_interval" type="text" /> <b>"days hours:minutes"</b>, default = 10 minutes');
|
||||
};
|
||||
|
||||
fFailedRequest = function(msg) {
|
||||
|
|
@ -89,7 +90,8 @@
|
|||
var evtFunc;
|
||||
evtFunc = $(this).val();
|
||||
if (evtFunc === '') {
|
||||
$('#input_interval').html('');
|
||||
$('#event_start').html('');
|
||||
$('#event_interval').html('');
|
||||
} else {
|
||||
fPlaceAndPaintInterval();
|
||||
}
|
||||
|
|
@ -101,7 +103,8 @@
|
|||
$('#select_event').val($(this).val());
|
||||
fFetchEventParams($('#select_event').val());
|
||||
if ($('#select_event').val() === '') {
|
||||
return $('#input_interval').html('');
|
||||
$('#event_start').html('');
|
||||
return $('#event_interval').html('');
|
||||
} else {
|
||||
return fPlaceAndPaintInterval();
|
||||
}
|
||||
|
|
@ -470,7 +473,7 @@
|
|||
return $(this).closest('tr').remove();
|
||||
});
|
||||
$('#but_submit').click(function() {
|
||||
var actFuncs, acts, ap, arrInp, conds, d, ep, err, eventId, evtFuncs, fCheckOverwrite, fParseTime, mins, txtInterval;
|
||||
var actFuncs, acts, ap, arrInp, conds, d, ep, err, eventId, evtFuncs, fCheckOverwrite, fParseTime, h, intHour, intMin, m, mins, start, txtHr, txtInterval, txtStart;
|
||||
window.scrollTo(0, 0);
|
||||
$('#info').text('');
|
||||
try {
|
||||
|
|
@ -565,8 +568,34 @@
|
|||
if (!(conds instanceof Array)) {
|
||||
throw new Error("Conditions Invalid! Needs to be an Array of Strings!");
|
||||
}
|
||||
txtStart = $('#input_start').val();
|
||||
start = new Date();
|
||||
if (!txtStart) {
|
||||
start.setHours(12);
|
||||
start.setMinutes(0);
|
||||
console.log('setting to 12:00: ' + start.toString());
|
||||
} else {
|
||||
arrInp = txtStart.split(':');
|
||||
if (arrInp.length === 1) {
|
||||
txtHr = txtStart;
|
||||
start.setMinutes(0);
|
||||
} else {
|
||||
txtHr = arrInp[0];
|
||||
intMin = parseInt(arrInp[1]) || 0;
|
||||
m = Math.max(0, Math.min(intMin, 59));
|
||||
start.setMinutes(m);
|
||||
}
|
||||
}
|
||||
intHour = parseInt(txtHr) || 12;
|
||||
h = Math.max(0, Math.min(intHour, 12));
|
||||
start.setHours(h);
|
||||
start.setSeconds(0);
|
||||
start.setMilliseconds(0);
|
||||
if (start < new Date()) {
|
||||
start.setDate(start.getDate() + 1);
|
||||
}
|
||||
fParseTime = function(str, hasDay) {
|
||||
var arrTime, def, h, time;
|
||||
var arrTime, def, time;
|
||||
arrTime = str.split(':');
|
||||
if (hasDay) {
|
||||
def = 0;
|
||||
|
|
@ -588,7 +617,7 @@
|
|||
return h * 60 + (parseInt(arrTime[1]) || def);
|
||||
}
|
||||
};
|
||||
txtInterval = $('#event_interval').val();
|
||||
txtInterval = $('#input_interval').val();
|
||||
if (!txtInterval) {
|
||||
mins = 10;
|
||||
} else {
|
||||
|
|
@ -626,6 +655,7 @@
|
|||
id: $('#input_id').val(),
|
||||
event: eventId,
|
||||
event_params: ep,
|
||||
event_start: start.toISOString(),
|
||||
event_interval: mins,
|
||||
event_functions: evtFuncs,
|
||||
conditions: conds,
|
||||
|
|
@ -655,7 +685,7 @@
|
|||
})
|
||||
};
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
var action, arrName, oRule, _j, _len1, _ref, _results;
|
||||
var action, arrName, d, mins, oRule, _j, _len1, _ref, _results;
|
||||
oRule = JSON.parse(data.message);
|
||||
if (oRule) {
|
||||
$('#input_id').val(oRule.id);
|
||||
|
|
@ -665,7 +695,13 @@
|
|||
fPlaceAndPaintInterval();
|
||||
}
|
||||
$('#input_event').val(oRule.event);
|
||||
$('#event_interval').val(oRule.event_interval);
|
||||
d = new Date(oRule.event_start);
|
||||
mins = d.getMinutes();
|
||||
if (mins.toString().length === 1) {
|
||||
mins = '0' + mins;
|
||||
}
|
||||
$('#input_start').val(d.getHours() + ':' + mins);
|
||||
$('#input_interval').val(oRule.event_interval);
|
||||
editor.setValue(JSON.stringify(oRule.conditions, void 0, 2));
|
||||
_ref = oRule.actions;
|
||||
_results = [];
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ Module Name: <input id="input_id" type="text" />
|
|||
<select id="editor_mode">
|
||||
<option>CoffeeScript</option>
|
||||
<option>JavaScript</option>
|
||||
</select> is public: <input type="checkbox" id="is_public" checked/>
|
||||
</select><!-- is public: <input type="checkbox" id="is_public" checked/> -->
|
||||
<table id="editor_table">
|
||||
<tr>
|
||||
<td id="editor_col" valign="top">
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
<b>Rule Name: </b><input id="input_id" type="text" /><br>
|
||||
<h2>EVENT</h2>
|
||||
<select id="select_event"><option></option></select><br/>
|
||||
<input id="input_event" type="text" /><br/>
|
||||
<div id="input_interval"></div><br/>
|
||||
<input id="input_event" type="text" /><br/><br/>
|
||||
<div id="event_start"></div>
|
||||
<div id="event_interval"></div><br/>
|
||||
<div id="event_poller_params"></div>
|
||||
<br>
|
||||
<h2>CONDITIONS</h2>
|
||||
|
|
|
|||
Loading…
Reference in a new issue