mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	support for backend jobs and other script API changes
This commit is contained in:
		| @@ -18,7 +18,40 @@ async function executeScript(dataKey, script, params) { | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| 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 setJob(opts) { | ||||
|     clearExistingJob(opts.name); | ||||
|  | ||||
|     if (opts.runEveryMs && opts.runEveryMs > 0) { | ||||
|         intervals[opts.name] = setInterval(() => executeScript(null, opts.job, opts.params), opts.runEveryMs); | ||||
|     } | ||||
|  | ||||
|     if (opts.initialRunAfterMs && opts.initialRunAfterMs > 0) { | ||||
|         timeouts[opts.name] = setTimeout(() => executeScript(null, opts.job, opts.params), opts.initialRunAfterMs); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function getParams(params) { | ||||
|     if (!params) { | ||||
|         return params; | ||||
|     } | ||||
|  | ||||
|     return params.map(p => { | ||||
|         if (typeof p === "string" && p.startsWith("!@#Function: ")) { | ||||
|             return p.substr(13); | ||||
| @@ -30,5 +63,6 @@ function getParams(params) { | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|     executeScript | ||||
|     executeScript, | ||||
|     setJob | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user