aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-02 15:29:00 +0200
committerChocobozzz <me@florianbigard.com>2022-08-02 15:50:05 +0200
commit22df69fdecf299c8be6acaa25f086249ea9a0085 (patch)
treee8c7e21c18fb42bb74b54f2eab1509c3d93a380d /shared/core-utils
parent7a9e420a02434e4f16c99e7d58da9075dff25d15 (diff)
downloadPeerTube-22df69fdecf299c8be6acaa25f086249ea9a0085.tar.gz
PeerTube-22df69fdecf299c8be6acaa25f086249ea9a0085.tar.zst
PeerTube-22df69fdecf299c8be6acaa25f086249ea9a0085.zip
Add job queue hooks
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/plugins/hooks.ts17
1 files changed, 13 insertions, 4 deletions
diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts
index 92cb5ad68..3784969b5 100644
--- a/shared/core-utils/plugins/hooks.ts
+++ b/shared/core-utils/plugins/hooks.ts
@@ -8,15 +8,24 @@ function getHookType (hookName: string) {
8 return HookType.STATIC 8 return HookType.STATIC
9} 9}
10 10
11async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { 11async function internalRunHook <T> (options: {
12 handler: Function
13 hookType: HookType
14 result: T
15 params: any
16 onError: (err: Error) => void
17}) {
18 const { handler, hookType, result, params, onError } = options
19
12 try { 20 try {
13 if (hookType === HookType.FILTER) { 21 if (hookType === HookType.FILTER) {
14 const p = handler(result, params) 22 const p = handler(result, params)
15 23
16 if (isPromise(p)) result = await p 24 const newResult = isPromise(p)
17 else result = p 25 ? await p
26 : p
18 27
19 return result 28 return newResult
20 } 29 }
21 30
22 // Action/static hooks do not have result value 31 // Action/static hooks do not have result value