mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
cleaned up unused jobs implementation
This commit is contained in:
parent
ddce5c959e
commit
07bf075894
@ -56,13 +56,6 @@ const server = (function() {
|
|||||||
return ret.executionResult;
|
return ret.executionResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setJob(opts) {
|
|
||||||
opts.job = opts.job.toString();
|
|
||||||
opts.params = prepareParams(opts.params);
|
|
||||||
|
|
||||||
await post('script/job', opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
let i = 1;
|
let i = 1;
|
||||||
const reqResolves = {};
|
const reqResolves = {};
|
||||||
|
|
||||||
@ -127,7 +120,6 @@ const server = (function() {
|
|||||||
put,
|
put,
|
||||||
remove,
|
remove,
|
||||||
exec,
|
exec,
|
||||||
setJob,
|
|
||||||
ajax,
|
ajax,
|
||||||
// don't remove, used from CKEditor image upload!
|
// don't remove, used from CKEditor image upload!
|
||||||
getHeaders
|
getHeaders
|
||||||
|
@ -16,12 +16,6 @@ router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.post('/job', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
||||||
await script.setJob(req.body);
|
|
||||||
|
|
||||||
res.send({});
|
|
||||||
}));
|
|
||||||
|
|
||||||
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
const repository = new Repository(req);
|
const repository = new Repository(req);
|
||||||
const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");
|
const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");
|
||||||
|
@ -34,51 +34,6 @@ async function execute(ctx, script, paramsStr) {
|
|||||||
return await (function() { return eval(`const api = this;\r\n(${script})(${paramsStr})`); }.call(ctx));
|
return await (function() { return eval(`const api = this;\r\n(${script})(${paramsStr})`); }.call(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeouts = {};
|
|
||||||
const intervals = {};
|
|
||||||
|
|
||||||
function clearExistingJob(name) {
|
|
||||||
if (timeouts[name]) {
|
|
||||||
clearTimeout(timeouts[name]);
|
|
||||||
|
|
||||||
delete timeouts[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intervals[name]) {
|
|
||||||
clearInterval(intervals[name]);
|
|
||||||
|
|
||||||
delete intervals[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function executeJob(script, params, manualTransactionHandling) {
|
|
||||||
const ctx = new ScriptContext();
|
|
||||||
const paramsStr = getParams(params);
|
|
||||||
|
|
||||||
if (manualTransactionHandling) {
|
|
||||||
return await execute(ctx, script, paramsStr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return await sql.doInTransaction(async () => execute(ctx, script, paramsStr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setJob(opts) {
|
|
||||||
const { name, runEveryMs, initialRunAfterMs } = opts;
|
|
||||||
|
|
||||||
clearExistingJob(name);
|
|
||||||
|
|
||||||
const jobFunc = () => executeJob(opts.job, opts.params, opts.manualTransactionHandling);
|
|
||||||
|
|
||||||
if (runEveryMs && runEveryMs > 0) {
|
|
||||||
intervals[name] = setInterval(jobFunc, runEveryMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (initialRunAfterMs && initialRunAfterMs > 0) {
|
|
||||||
timeouts[name] = setTimeout(jobFunc, initialRunAfterMs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getParams(params) {
|
function getParams(params) {
|
||||||
if (!params) {
|
if (!params) {
|
||||||
return params;
|
return params;
|
||||||
@ -152,7 +107,6 @@ ${note.content}
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
executeNote,
|
executeNote,
|
||||||
executeScript,
|
executeScript,
|
||||||
setJob,
|
|
||||||
getScriptBundle,
|
getScriptBundle,
|
||||||
getRenderScript
|
getRenderScript
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user