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

26
src/services/scheduler.js Normal file
View File

@@ -0,0 +1,26 @@
const script = require('./script');
const Repository = require('./repository');
const repo = new Repository();
async function runNotesWithAttribute(runAttrValue) {
const notes = await repo.getEntities(`
SELECT notes.*
FROM notes
JOIN attributes ON attributes.noteId = notes.noteId
AND attributes.name = 'run'
AND attributes.value = ?
WHERE
notes.type = 'code'
AND notes.isDeleted = 0`, [runAttrValue]);
for (const note of notes) {
script.executeNote(note);
}
}
setTimeout(() => runNotesWithAttribute('on_startup'), 10 * 1000);
setInterval(() => runNotesWithAttribute('hourly'), 3600 * 1000);
setInterval(() => runNotesWithAttribute('daily'), 24 * 3600 * 1000);