trilium/src/services/scheduler.js

26 lines
870 B
JavaScript
Raw Normal View History

const scriptService = require('./script');
2018-03-31 21:07:58 +08:00
const repository = require('./repository');
const cls = require('./cls');
async function runNotesWithLabel(runAttrValue) {
2018-03-31 21:07:58 +08:00
const notes = await repository.getEntities(`
SELECT notes.*
FROM notes
JOIN labels ON labels.noteId = notes.noteId
AND labels.isDeleted = 0
AND labels.name = 'run'
AND labels.value = ?
WHERE
notes.type = 'code'
AND notes.isDeleted = 0`, [runAttrValue]);
for (const note of notes) {
scriptService.executeNote(note);
}
}
2018-04-05 11:04:31 +08:00
setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000);
2018-04-05 11:04:31 +08:00
setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000);
2018-04-05 11:04:31 +08:00
setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000);