mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add job queue hooks
This commit is contained in:
parent
7a9e420a02
commit
22df69fdec
12 changed files with 151 additions and 26 deletions
|
@ -8,15 +8,24 @@ function getHookType (hookName: string) {
|
|||
return HookType.STATIC
|
||||
}
|
||||
|
||||
async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) {
|
||||
async function internalRunHook <T> (options: {
|
||||
handler: Function
|
||||
hookType: HookType
|
||||
result: T
|
||||
params: any
|
||||
onError: (err: Error) => void
|
||||
}) {
|
||||
const { handler, hookType, result, params, onError } = options
|
||||
|
||||
try {
|
||||
if (hookType === HookType.FILTER) {
|
||||
const p = handler(result, params)
|
||||
|
||||
if (isPromise(p)) result = await p
|
||||
else result = p
|
||||
const newResult = isPromise(p)
|
||||
? await p
|
||||
: p
|
||||
|
||||
return result
|
||||
return newResult
|
||||
}
|
||||
|
||||
// Action/static hooks do not have result value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue