2018-03-03 09:56:58 +08:00
|
|
|
const script = require('./script');
|
|
|
|
const Repository = require('./repository');
|
|
|
|
|
|
|
|
const repo = new Repository();
|
|
|
|
|
2018-03-25 10:02:26 +08:00
|
|
|
async function runNotesWithLabel(runAttrValue) {
|
2018-03-03 09:56:58 +08:00
|
|
|
const notes = await repo.getEntities(`
|
|
|
|
SELECT notes.*
|
|
|
|
FROM notes
|
2018-03-25 10:02:26 +08:00
|
|
|
JOIN labels ON labels.noteId = notes.noteId
|
|
|
|
AND labels.isDeleted = 0
|
|
|
|
AND labels.name = 'run'
|
|
|
|
AND labels.value = ?
|
2018-03-03 09:56:58 +08:00
|
|
|
WHERE
|
|
|
|
notes.type = 'code'
|
|
|
|
AND notes.isDeleted = 0`, [runAttrValue]);
|
|
|
|
|
|
|
|
for (const note of notes) {
|
2018-03-07 12:04:35 +08:00
|
|
|
script.executeNote(null, note);
|
2018-03-03 09:56:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 10:02:26 +08:00
|
|
|
setTimeout(() => runNotesWithLabel('backend_startup'), 10 * 1000);
|
2018-03-03 09:56:58 +08:00
|
|
|
|
2018-03-25 10:02:26 +08:00
|
|
|
setInterval(() => runNotesWithLabel('hourly'), 3600 * 1000);
|
2018-03-03 09:56:58 +08:00
|
|
|
|
2018-03-25 10:02:26 +08:00
|
|
|
setInterval(() => runNotesWithLabel('daily'), 24 * 3600 * 1000);
|