basic scheduling of backend scripts using attributes

This commit is contained in:
azivner
2018-03-02 20:56:58 -05:00
parent 31d5ac05ff
commit 982b723647
4 changed files with 43 additions and 1 deletions

View File

@@ -1,6 +1,18 @@
const sql = require('./sql');
const ScriptContext = require('./script_context');
async function executeNote(note) {
if (note.isProtected || !note.isJavaScript()) {
return;
}
const ctx = new ScriptContext();
return await sql.doInTransaction(async () => {
return await (function() { return eval(`const api = this; (async function() {${note.content}\n\r})()`); }.call(ctx));
});
}
async function executeScript(dataKey, script, params) {
const ctx = new ScriptContext(dataKey);
const paramsStr = getParams(params);
@@ -73,6 +85,7 @@ function getParams(params) {
}
module.exports = {
executeNote,
executeScript,
setJob
};