2018-04-02 09:27:46 +08:00
|
|
|
const scriptService = require('./script');
|
2018-03-31 21:07:58 +08:00
|
|
|
const repository = require('./repository');
|
2018-03-29 11:41:22 +08:00
|
|
|
const cls = require('./cls');
|
2018-04-06 11:17:19 +08:00
|
|
|
const sqlInit = require('./sql_init');
|
2018-03-03 09:56:58 +08:00
|
|
|
|
2018-03-25 10:02:26 +08:00
|
|
|
async function runNotesWithLabel(runAttrValue) {
|
2018-03-31 21:07:58 +08:00
|
|
|
const notes = await repository.getEntities(`
|
2018-03-03 09:56:58 +08:00
|
|
|
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-04-02 09:27:46 +08:00
|
|
|
scriptService.executeNote(note);
|
2018-03-03 09:56:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 11:17:19 +08:00
|
|
|
sqlInit.dbReady.then(() => {
|
|
|
|
setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000);
|
2018-03-03 09:56:58 +08:00
|
|
|
|
2018-04-06 11:17:19 +08:00
|
|
|
setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000);
|
2018-03-03 09:56:58 +08:00
|
|
|
|
2018-04-06 11:17:19 +08:00
|
|
|
setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000);
|
|
|
|
});
|