2018-03-03 09:56:58 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 11:09:51 +08:00
|
|
|
setTimeout(() => runNotesWithAttribute('backend_startup'), 10 * 1000);
|
2018-03-03 09:56:58 +08:00
|
|
|
|
|
|
|
setInterval(() => runNotesWithAttribute('hourly'), 3600 * 1000);
|
|
|
|
|
|
|
|
setInterval(() => runNotesWithAttribute('daily'), 24 * 3600 * 1000);
|