-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: async tasker for google calendar events #23494
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
Changes from all commits
6e7c8f0
a11c2d0
d6681b4
23b34e5
c861815
bdd2593
be5b70e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ | |
| "@axiomhq/winston": "^1.2.0", | ||
| "@calcom/platform-constants": "*", | ||
| "@calcom/platform-enums": "*", | ||
| "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.335", | ||
| "@calcom/platform-libraries": "npm:@calcom/platform-libraries@9.9.9", | ||
|
Contributor
Author
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. publish libraries before merge |
||
| "@calcom/platform-types": "*", | ||
| "@calcom/platform-utils": "*", | ||
| "@calcom/prisma": "*", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Logger } from "@/lib/logger.bridge"; | ||
| import { GoogleCalendarSyncTasker } from "@/lib/services/taskers/google-calendar-sync-tasker.service"; | ||
| import { GoogleCalendarTasker } from "@/lib/services/taskers/google-calendar-tasker.service"; | ||
| import { GoogleCalendarTriggerDevTasker } from "@/lib/services/taskers/google-calendar-trigger-tasker.service"; | ||
| import { Module } from "@nestjs/common"; | ||
|
|
||
| @Module({ | ||
| imports: [], | ||
| providers: [GoogleCalendarSyncTasker, GoogleCalendarTriggerDevTasker, Logger, GoogleCalendarTasker], | ||
| exports: [GoogleCalendarTasker], | ||
| }) | ||
| export class GoogleCalendarTaskerModule {} | ||
|
Comment on lines
+1
to
+12
Contributor
Author
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. module which can be used within api v2 controller to inject google calendar tasker |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Logger } from "@/lib/logger.bridge"; | ||
| import { Injectable } from "@nestjs/common"; | ||
|
|
||
| import { GoogleCalendarSyncTasker as BaseGoogleCalendarSyncTasker } from "@calcom/platform-libraries/taskers"; | ||
|
|
||
| @Injectable() | ||
| export class GoogleCalendarSyncTasker extends BaseGoogleCalendarSyncTasker { | ||
| constructor(logger: Logger) { | ||
| super({ | ||
| logger, | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Logger } from "@/lib/logger.bridge"; | ||
| import { Injectable } from "@nestjs/common"; | ||
|
|
||
| import { GoogleCalendarTasker as BaseGoogleCalendarTasker } from "@calcom/platform-libraries/taskers"; | ||
|
|
||
| import { GoogleCalendarSyncTasker } from "./google-calendar-sync-tasker.service"; | ||
| import { GoogleCalendarTriggerDevTasker } from "./google-calendar-trigger-tasker.service"; | ||
|
|
||
| @Injectable() | ||
| export class GoogleCalendarTasker extends BaseGoogleCalendarTasker { | ||
| constructor( | ||
| primaryTasker: GoogleCalendarTriggerDevTasker, | ||
|
Contributor
Author
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. for example here: ApiV2 could provide it's own BullMQ tasker
Contributor
Author
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. and this could also be controller by env variable |
||
| fallbackTasker: GoogleCalendarSyncTasker, | ||
| logger: Logger | ||
| ) { | ||
| super({ | ||
| primaryTasker: primaryTasker, | ||
| fallbackTasker: fallbackTasker, | ||
| logger, | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Logger } from "@/lib/logger.bridge"; | ||
| import { Injectable } from "@nestjs/common"; | ||
|
|
||
| import { GoogleCalendarTriggerDevTasker as BaseGoogleCalendarTriggerDevTasker } from "@calcom/platform-libraries/taskers"; | ||
|
|
||
| @Injectable() | ||
| export class GoogleCalendarTriggerDevTasker extends BaseGoogleCalendarTriggerDevTasker { | ||
| constructor(logger: Logger) { | ||
| super({ | ||
| logger, | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,7 +28,8 @@ | |||||||
| "@calcom/platform-libraries/conferencing": ["../../../packages/platform/libraries/conferencing.ts"], | ||||||||
| "@calcom/platform-libraries/repositories": ["../../../packages/platform/libraries/repositories.ts"], | ||||||||
| "@calcom/platform-libraries/bookings": ["../../../packages/platform/libraries/bookings.ts"], | ||||||||
| "@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"] | ||||||||
| "@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"], | ||||||||
| "@calcom/platform-libraries/taskers": ["../../../packages/platform/libraries/taskers.ts"] | ||||||||
|
Comment on lines
+31
to
+32
Contributor
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. 🛠️ Refactor suggestion Path alias overrides the package export; remove it to avoid split sources. @calcom/platform-libraries now exports "taskers". Keeping this alias points imports to a raw TS file and can desync with the published package. Remove the alias and fix the dangling comma. - "@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"],
- "@calcom/platform-libraries/taskers": ["../../../packages/platform/libraries/taskers.ts"]
+ "@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| }, | ||||||||
| "incremental": true, | ||||||||
| "skipLibCheck": true, | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // No need for a generic base 'TaskerInterface'. We will use the specific domain interface directly. | ||
| // For example, ICalendarTasker. | ||
| import type { ILogger } from "./types/logger"; | ||
|
|
||
| export abstract class BaseTaskerService<T> { | ||
| // T is now just a placeholder for the class that extends this | ||
| // The dependencies are now typed with the specific interfaces | ||
| protected readonly primaryTasker: T; | ||
| protected readonly fallbackTasker: T; | ||
| protected readonly logger: ILogger; | ||
|
|
||
| constructor(dependencies: { primaryTasker: T; fallbackTasker: T; logger: ILogger }) { | ||
| this.primaryTasker = dependencies.primaryTasker; | ||
| this.fallbackTasker = dependencies.fallbackTasker; | ||
| this.logger = dependencies.logger; | ||
| } | ||
|
|
||
| public async dispatch<K extends keyof T>( | ||
| taskName: K, | ||
| ...args: T[K] extends (...args: any[]) => any ? Parameters<T[K]> : never | ||
| ): Promise<T[K] extends (...args: any[]) => any ? Awaited<ReturnType<T[K]>> : never> { | ||
| this.logger.info(`Dispatching task '${String(taskName)}'`, { args }); | ||
| return this.safeDispatch(taskName, ...args); | ||
| } | ||
|
|
||
| // The dispatch method is now strongly typed to the keys of T | ||
| protected async safeDispatch<K extends keyof T>( | ||
| taskName: K, | ||
| // We infer the arguments directly from the method on T | ||
| ...args: T[K] extends (...args: any[]) => any ? Parameters<T[K]> : never | ||
| ): Promise<T[K] extends (...args: any[]) => any ? Awaited<ReturnType<T[K]>> : never> { | ||
| try { | ||
| const method = this.primaryTasker[taskName] as (...args: any[]) => any; | ||
| return await method.apply(this.primaryTasker, args); | ||
| } catch (err) { | ||
| this.logger.error(`Primary tasker failed for '${String(taskName)}'.`, err as Error); | ||
|
|
||
| if (this.primaryTasker === this.fallbackTasker) { | ||
| throw err; | ||
| } | ||
|
|
||
| this.logger.warn(`Falling back to SyncTasker for '${String(taskName)}'.`); | ||
|
|
||
| const fallbackMethod = this.fallbackTasker[taskName] as (...args: any[]) => any; | ||
| return fallbackMethod.apply(this.fallbackTasker, args); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+48
Contributor
Author
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. this is the base tasker class which specialized taskers will extends, this ensures the fallback tasker is called if the primary tasker fails (for example is trigger.dev is down)
Contributor
Author
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. this also abstract the logic of dispatch and safeDispatch so that people implementing Specialized taskers do not have to worry with it |
||
Uh oh!
There was an error while loading. Please reload this page.