-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix webhook issue #6711
Merged
+28
−30
Merged
Fix webhook issue #6711
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d65b05f
Temp logs
charlesBochet 3744da4
Fix
charlesBochet 678bc66
Remove logs
charlesBochet d9ec628
Remove unused ids
charlesBochet 2442e3a
Fix webhook issue
charlesBochet 0fe882a
Merge branch 'main' into fix-webhook-issue
charlesBochet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,4 @@ | |
} | ||
], | ||
"extends": "../../tsconfig.base.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { Logger } from '@nestjs/common'; | ||
|
||
import { Like } from 'typeorm'; | ||
|
||
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface'; | ||
|
||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service'; | ||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service'; | ||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; | ||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; | ||
import { | ||
CallWebhookJob, | ||
CallWebhookJobData, | ||
} from 'src/engine/api/graphql/workspace-query-runner/jobs/call-webhook.job'; | ||
import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator'; | ||
import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; | ||
import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator'; | ||
import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator'; | ||
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants'; | ||
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service'; | ||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager'; | ||
import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity'; | ||
|
||
export enum CallWebhookJobsJobOperation { | ||
create = 'create', | ||
|
@@ -32,42 +34,38 @@ export class CallWebhookJobsJob { | |
private readonly logger = new Logger(CallWebhookJobsJob.name); | ||
|
||
constructor( | ||
private readonly workspaceDataSourceService: WorkspaceDataSourceService, | ||
private readonly dataSourceService: DataSourceService, | ||
@InjectMessageQueue(MessageQueue.webhookQueue) | ||
private readonly messageQueueService: MessageQueueService, | ||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager, | ||
) {} | ||
|
||
@Process(CallWebhookJobsJob.name) | ||
async handle(data: CallWebhookJobsJobData): Promise<void> { | ||
const dataSourceMetadata = | ||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceIdOrFail( | ||
data.workspaceId, | ||
); | ||
const workspaceDataSource = | ||
await this.workspaceDataSourceService.connectToWorkspaceDataSource( | ||
const webhookRepository = | ||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WebhookWorkspaceEntity>( | ||
data.workspaceId, | ||
'webhook', | ||
); | ||
|
||
const nameSingular = data.objectMetadataItem.nameSingular; | ||
const operation = data.operation; | ||
const eventType = `${operation}.${nameSingular}`; | ||
const webhooks: { id: string; targetUrl: string }[] = | ||
await workspaceDataSource?.query( | ||
` | ||
SELECT * FROM ${dataSourceMetadata.schema}."webhook" | ||
WHERE operation LIKE '%${eventType}%' | ||
OR operation LIKE '%*.${nameSingular}%' | ||
OR operation LIKE '%${operation}.*%' | ||
OR operation LIKE '%*.*%' | ||
`, | ||
); | ||
const eventName = `${nameSingular}.${operation}`; | ||
|
||
const webhooks = await webhookRepository.find({ | ||
where: [ | ||
{ operation: Like(`%${eventName}%`) }, | ||
{ operation: Like(`%*.${operation}%`) }, | ||
{ operation: Like(`%${nameSingular}.*%`) }, | ||
{ operation: Like('%*.*%') }, | ||
], | ||
}); | ||
|
||
webhooks.forEach((webhook) => { | ||
this.messageQueueService.add<CallWebhookJobData>( | ||
CallWebhookJob.name, | ||
{ | ||
targetUrl: webhook.targetUrl, | ||
eventType, | ||
eventName, | ||
objectMetadata: { | ||
id: data.objectMetadataItem.id, | ||
nameSingular: data.objectMetadataItem.nameSingular, | ||
|
@@ -83,7 +81,7 @@ export class CallWebhookJobsJob { | |
|
||
if (webhooks.length) { | ||
this.logger.log( | ||
`CallWebhookJobsJob on eventType '${eventType}' called on webhooks ids [\n"${webhooks | ||
`CallWebhookJobsJob on eventName '${event}' called on webhooks ids [\n"${webhooks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: 'event' is undefined. Should be 'eventName'. |
||
.map((webhook) => webhook.id) | ||
.join('",\n"')}"\n]`, | ||
); | ||
|
6 changes: 3 additions & 3 deletions
6
...ages/twenty-server/src/engine/api/graphql/workspace-query-runner/jobs/call-webhook.job.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using an array of strings for operations and use
In
operator instead of multipleLike
conditions for better performance.