mirror of https://github.com/nocodb/nocodb
Browse Source
* fix: only pause queue once for non-worker * fix: move error handling inside loop * fix: avoid unhandled reject * fix: return original template if parsing failed * fix: remove jobs on complete * fix: remove job on complete Signed-off-by: mertmit <mertmit99@gmail.com> * fix: move wh job handler to invokeWebhook Signed-off-by: mertmit <mertmit99@gmail.com> * refactor: import from barrel Signed-off-by: mertmit <mertmit99@gmail.com> * fix: improve reduce logic Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: type issues Signed-off-by: mertmit <mertmit99@gmail.com> --------- Signed-off-by: mertmit <mertmit99@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>pull/8601/head
Mert E
6 months ago
committed by
GitHub
10 changed files with 164 additions and 138 deletions
@ -1,24 +1,45 @@
|
||||
import { Process, Processor } from '@nestjs/bull'; |
||||
import { forwardRef, Inject, Logger } from '@nestjs/common'; |
||||
import { Logger } from '@nestjs/common'; |
||||
import { Job } from 'bull'; |
||||
import { invokeWebhook } from '~/helpers/webhookHelpers'; |
||||
import { Hook, Model, View } from '~/models'; |
||||
import { |
||||
type HandleWebhookJobData, |
||||
JOBS_QUEUE, |
||||
JobTypes, |
||||
} from '~/interface/Jobs'; |
||||
import { HookHandlerService } from '~/services/hook-handler.service'; |
||||
|
||||
@Processor(JOBS_QUEUE) |
||||
export class WebhookHandlerProcessor { |
||||
private logger = new Logger(WebhookHandlerProcessor.name); |
||||
|
||||
constructor( |
||||
@Inject(forwardRef(() => HookHandlerService)) |
||||
private readonly hookHandlerService: HookHandlerService, |
||||
) {} |
||||
constructor() {} |
||||
|
||||
@Process(JobTypes.HandleWebhook) |
||||
async job(job: Job<HandleWebhookJobData>) { |
||||
await this.hookHandlerService.handleHooks(job.data); |
||||
const { hookId, modelId, viewId, prevData, newData, user } = job.data; |
||||
|
||||
const hook = await Hook.get(hookId); |
||||
if (!hook) { |
||||
this.logger.error(`Hook not found for id: ${hookId}`); |
||||
return; |
||||
} |
||||
|
||||
const model = await Model.get(modelId); |
||||
if (!model) { |
||||
this.logger.error(`Model not found for id: ${modelId}`); |
||||
return; |
||||
} |
||||
|
||||
const view = viewId ? await View.get(viewId) : null; |
||||
|
||||
await invokeWebhook({ |
||||
hook, |
||||
model, |
||||
view, |
||||
prevData, |
||||
newData, |
||||
user, |
||||
}); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue