Skip to content

The open alternative to Salesforce, designed for AI.

Call recorder: spread the upcoming calendar events sweep across workspaces (#27716)

nitin56afc5faa0ba
diff --git a/packages/twenty-apps/public/call-recorder/package.json b/packages/twenty-apps/public/call-recorder/package.json
index 3c4ba18d0aa..375934f17d5 100644
--- a/packages/twenty-apps/public/call-recorder/package.json
+++ b/packages/twenty-apps/public/call-recorder/package.json
@@ -1,6 +1,6 @@
{
"name": "@twentyhq/call-recorder",
- "version": "1.15.0",
+ "version": "1.15.1",
"license": "MIT",
"engines": {
"node": "^24.5.0",
diff --git a/packages/twenty-apps/public/call-recorder/src/constants/universal-identifiers.ts b/packages/twenty-apps/public/call-recorder/src/constants/universal-identifiers.ts
index 2dd5a1812aa..4537fa7ebbf 100644
--- a/packages/twenty-apps/public/call-recorder/src/constants/universal-identifiers.ts
+++ b/packages/twenty-apps/public/call-recorder/src/constants/universal-identifiers.ts
@@ -88,6 +88,9 @@ export const ENQUEUE_CALL_RECORDING_RECOVERY_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER
export const ENQUEUE_ORPHANED_RECALL_BOT_CLEANUP_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =
'455458ce-bbc3-4b39-a3f2-950540c9eda7';
+export const ENQUEUE_UPCOMING_CALENDAR_EVENTS_SWEEP_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =
+ 'b81499b0-af5b-4b30-8bf8-ba54ea0bad5f';
+
export const FOLLOW_UP_CALL_RECORDING_REQUEST_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =
'3e362527-0f8a-432b-94ea-95909a8e49ea';
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/__tests__/sweep-upcoming-calendar-events.test.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/__tests__/sweep-upcoming-calendar-events.test.ts
index f73e35127b5..06e06863e80 100644
--- a/packages/twenty-apps/public/call-recorder/src/logic-functions/__tests__/sweep-upcoming-calendar-events.test.ts
+++ b/packages/twenty-apps/public/call-recorder/src/logic-functions/__tests__/sweep-upcoming-calendar-events.test.ts
@@ -43,14 +43,14 @@ describe('sweepUpcomingCalendarEventsHandler', () => {
}));
});
- it('is configured as a daily cron', () => {
+ it('has no cron trigger of its own', () => {
expect(sweepLogicFunction.config).toEqual(
expect.objectContaining({
name: 'sweep-upcoming-calendar-events',
timeoutSeconds: 900,
- cronTriggerSettings: { pattern: '0 4 * * *' },
}),
);
+ expect(sweepLogicFunction.config.cronTriggerSettings).toBeUndefined();
});
it('enqueues one reconciliation batch for the upcoming calendar events', async () => {
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/enqueue-upcoming-calendar-events-sweep.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/enqueue-upcoming-calendar-events-sweep.ts
new file mode 100644
index 00000000000..87506c5977a
--- /dev/null
+++ b/packages/twenty-apps/public/call-recorder/src/logic-functions/enqueue-upcoming-calendar-events-sweep.ts
@@ -0,0 +1,36 @@
+import { type LogicFunctionExecutionContext } from 'twenty-sdk/logic-function';
+import { defineLogicFunction } from 'twenty-sdk/define';
+
+import {
+ ENQUEUE_UPCOMING_CALENDAR_EVENTS_SWEEP_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
+ SWEEP_UPCOMING_CALENDAR_EVENTS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
+} from 'src/constants/universal-identifiers';
+import { UPCOMING_CALENDAR_EVENTS_SWEEP_CRON_PATTERN } from 'src/logic-functions/constants/upcoming-calendar-events-sweep-cron-pattern';
+import {
+ enqueueWorkspaceDistributedJob,
+ type EnqueueWorkspaceDistributedJobResult,
+} from 'src/logic-functions/data/enqueue-workspace-distributed-job.util';
+
+export const enqueueUpcomingCalendarEventsSweepHandler = (
+ _payload: unknown,
+ { workspaceId }: LogicFunctionExecutionContext,
+): Promise<EnqueueWorkspaceDistributedJobResult> =>
+ enqueueWorkspaceDistributedJob({
+ workspaceId,
+ logicFunctionUniversalIdentifier:
+ SWEEP_UPCOMING_CALENDAR_EVENTS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
+ stepLabel: 'upcoming calendar events sweep enqueueing',
+ });
+
+export default defineLogicFunction({
+ universalIdentifier:
+ ENQUEUE_UPCOMING_CALENDAR_EVENTS_SWEEP_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
+ name: 'enqueue-upcoming-calendar-events-sweep',
+ description:
+ 'Enqueues the upcoming calendar events sweep at a stable workspace-specific delay to distribute Twenty API traffic.',
+ timeoutSeconds: 30,
+ handler: enqueueUpcomingCalendarEventsSweepHandler,
+ cronTriggerSettings: {
+ pattern: UPCOMING_CALENDAR_EVENTS_SWEEP_CRON_PATTERN,
+ },
+});
diff --git a/packages/twenty-apps/public/call-recorder/src/logic-functions/sweep-upcoming-calendar-events.ts b/packages/twenty-apps/public/call-recorder/src/logic-functions/sweep-upcoming-calendar-events.ts
index 304bf5aaa7b..036d99cff8d 100644
--- a/packages/twenty-apps/public/call-recorder/src/logic-functions/sweep-upcoming-calendar-events.ts
+++ b/packages/twenty-apps/public/call-recorder/src/logic-functions/sweep-upcoming-calendar-events.ts
@@ -6,10 +6,10 @@ import {
SWEEP_UPCOMING_CALENDAR_EVENTS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
} from 'src/constants/universal-identifiers';
import { UPCOMING_CALENDAR_EVENT_RECONCILIATION_BATCH_SIZE } from 'src/logic-functions/constants/upcoming-calendar-event-reconciliation-batch-size';
-import { UPCOMING_CALENDAR_EVENTS_SWEEP_CRON_PATTERN } from 'src/logic-functions/constants/upcoming-calendar-events-sweep-cron-pattern';
import { enqueueLogicFunctionJobs } from 'src/logic-functions/data/enqueue-logic-function-jobs.util';
import { fetchUpcomingCalendarEventIds } from 'src/logic-functions/data/fetch-upcoming-calendar-event-ids.util';
import { buildRetryableStepFailure } from 'src/logic-functions/utils/build-step-failure.util';
+import { fetchWithRateLimitRetry } from 'src/logic-functions/utils/fetch-with-rate-limit-retry.util';
import { getBatches } from 'src/logic-functions/utils/get-batches.util';
type SweepUpcomingCalendarEventsResult =
@@ -23,7 +23,7 @@ type SweepUpcomingCalendarEventsResult =
export const sweepUpcomingCalendarEventsHandler =
async (): Promise<SweepUpcomingCalendarEventsResult> => {
try {
- const client = new CoreApiClient();
+ const client = new CoreApiClient({ fetch: fetchWithRateLimitRetry });
const calendarEventIds = await fetchUpcomingCalendarEventIds(
client,
@@ -62,10 +62,7 @@ export default defineLogicFunction({
SWEEP_UPCOMING_CALENDAR_EVENTS_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,
name: 'sweep-upcoming-calendar-events',
description:
- 'Enqueues one reconciliation batch per group of upcoming calendar events on a schedule so meetings entering the scheduling horizon get their recording bots.',
+ 'Enqueues one reconciliation batch per group of upcoming calendar events so meetings entering the scheduling horizon get their recording bots.',
timeoutSeconds: 900,
handler: sweepUpcomingCalendarEventsHandler,
- cronTriggerSettings: {
- pattern: UPCOMING_CALENDAR_EVENTS_SWEEP_CRON_PATTERN,
- },
});