diff --git a/services/apps/merge_suggestions_worker/src/schedules/memberMergeSuggestions.ts b/services/apps/merge_suggestions_worker/src/schedules/memberMergeSuggestions.ts index 039f4acc70..ceaae512bf 100644 --- a/services/apps/merge_suggestions_worker/src/schedules/memberMergeSuggestions.ts +++ b/services/apps/merge_suggestions_worker/src/schedules/memberMergeSuggestions.ts @@ -1,35 +1,30 @@ import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client' -import { IS_DEV_ENV, IS_TEST_ENV } from '@crowd/common' +import { DEFAULT_TENANT_ID } from '@crowd/common' import { svc } from '../main' -import { spawnMemberMergeSuggestionsForAllTenants } from '../workflows/spawnMemberMergeSuggestionsForAllTenants' +import { generateMemberMergeSuggestions } from '../workflows/generateMemberMergeSuggestions' export const scheduleGenerateMemberMergeSuggestions = async () => { try { await svc.temporal.schedule.create({ scheduleId: 'member-merge-suggestions', - spec: - IS_DEV_ENV || IS_TEST_ENV - ? { - cronExpressions: ['*/2 * * * *'], - } - : { - intervals: [ - { - every: '2 hours', - }, - ], - }, + spec: { + cronExpressions: ['0 */2 * * *'], + }, policies: { overlap: ScheduleOverlapPolicy.BUFFER_ONE, catchupWindow: '1 minute', }, action: { type: 'startWorkflow', - workflowType: spawnMemberMergeSuggestionsForAllTenants, + workflowType: generateMemberMergeSuggestions, taskQueue: 'merge-suggestions', - workflowExecutionTimeout: '5 minutes', + args: [ + { + tenantId: DEFAULT_TENANT_ID, + }, + ], }, }) } catch (err) { diff --git a/services/apps/merge_suggestions_worker/src/schedules/organizationMergeSuggestions.ts b/services/apps/merge_suggestions_worker/src/schedules/organizationMergeSuggestions.ts index aca1bd85c0..c3c1d70081 100644 --- a/services/apps/merge_suggestions_worker/src/schedules/organizationMergeSuggestions.ts +++ b/services/apps/merge_suggestions_worker/src/schedules/organizationMergeSuggestions.ts @@ -1,35 +1,30 @@ import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client' -import { IS_DEV_ENV, IS_TEST_ENV } from '@crowd/common' +import { DEFAULT_TENANT_ID } from '@crowd/common' import { svc } from '../main' -import { spawnOrganizationMergeSuggestionsForAllTenants } from '../workflows/spawnOrganizationMergeSuggestionsForAllTenants' +import { generateOrganizationMergeSuggestions } from '../workflows/generateOrganizationMergeSuggestions' export const scheduleGenerateOrganizationMergeSuggestions = async () => { try { await svc.temporal.schedule.create({ scheduleId: 'organization-merge-suggestions', - spec: - IS_DEV_ENV || IS_TEST_ENV - ? { - cronExpressions: ['*/2 * * * *'], - } - : { - intervals: [ - { - every: '2 hours', - }, - ], - }, + spec: { + cronExpressions: ['0 */2 * * *'], + }, policies: { overlap: ScheduleOverlapPolicy.BUFFER_ONE, catchupWindow: '1 minute', }, action: { type: 'startWorkflow', - workflowType: spawnOrganizationMergeSuggestionsForAllTenants, + workflowType: generateOrganizationMergeSuggestions, taskQueue: 'merge-suggestions', - workflowExecutionTimeout: '5 minutes', + args: [ + { + tenantId: DEFAULT_TENANT_ID, + }, + ], }, }) } catch (err) { diff --git a/services/apps/merge_suggestions_worker/src/workflows.ts b/services/apps/merge_suggestions_worker/src/workflows.ts index 488e8d71a3..5eef9a9fcc 100644 --- a/services/apps/merge_suggestions_worker/src/workflows.ts +++ b/services/apps/merge_suggestions_worker/src/workflows.ts @@ -2,15 +2,11 @@ import { generateMemberMergeSuggestions } from './workflows/generateMemberMergeS import { generateOrganizationMergeSuggestions } from './workflows/generateOrganizationMergeSuggestions' import { mergeMembersWithLLM } from './workflows/mergeMembersWithLLM' import { mergeOrganizationsWithLLM } from './workflows/mergeOrganizationsWithLLM' -import { spawnMemberMergeSuggestionsForAllTenants } from './workflows/spawnMemberMergeSuggestionsForAllTenants' -import { spawnOrganizationMergeSuggestionsForAllTenants } from './workflows/spawnOrganizationMergeSuggestionsForAllTenants' import { testMergingEntitiesWithLLM } from './workflows/testMergingEntitiesWithLLM' export { generateMemberMergeSuggestions, - spawnMemberMergeSuggestionsForAllTenants, generateOrganizationMergeSuggestions, - spawnOrganizationMergeSuggestionsForAllTenants, testMergingEntitiesWithLLM, mergeOrganizationsWithLLM, mergeMembersWithLLM, diff --git a/services/apps/merge_suggestions_worker/src/workflows/spawnMemberMergeSuggestionsForAllTenants.ts b/services/apps/merge_suggestions_worker/src/workflows/spawnMemberMergeSuggestionsForAllTenants.ts deleted file mode 100644 index fe9a89e1bd..0000000000 --- a/services/apps/merge_suggestions_worker/src/workflows/spawnMemberMergeSuggestionsForAllTenants.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - ChildWorkflowCancellationType, - ParentClosePolicy, - proxyActivities, - startChild, - workflowInfo, -} from '@temporalio/workflow' - -import * as activities from '../activities/common' - -import { generateMemberMergeSuggestions } from './generateMemberMergeSuggestions' - -const activity = proxyActivities({ startToCloseTimeout: '1 minute' }) - -export async function spawnMemberMergeSuggestionsForAllTenants(): Promise { - const tenants = await activity.getAllTenants() - const info = workflowInfo() - await Promise.all( - tenants.map((tenant) => { - return startChild(generateMemberMergeSuggestions, { - workflowId: `${info.workflowId}/${tenant.tenantId}`, - cancellationType: ChildWorkflowCancellationType.ABANDON, - parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON, - retry: { - backoffCoefficient: 2, - initialInterval: 2 * 1000, - maximumInterval: 30 * 1000, - }, - args: [ - { - tenantId: tenant.tenantId, - }, - ], - searchAttributes: { - TenantId: [tenant.tenantId], - }, - }) - }), - ) -} diff --git a/services/apps/merge_suggestions_worker/src/workflows/spawnOrganizationMergeSuggestionsForAllTenants.ts b/services/apps/merge_suggestions_worker/src/workflows/spawnOrganizationMergeSuggestionsForAllTenants.ts deleted file mode 100644 index fe0b335917..0000000000 --- a/services/apps/merge_suggestions_worker/src/workflows/spawnOrganizationMergeSuggestionsForAllTenants.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - ChildWorkflowCancellationType, - ParentClosePolicy, - proxyActivities, - startChild, - workflowInfo, -} from '@temporalio/workflow' - -import * as activities from '../activities/common' - -import { generateOrganizationMergeSuggestions } from './generateOrganizationMergeSuggestions' - -const activity = proxyActivities({ startToCloseTimeout: '1 minute' }) - -export async function spawnOrganizationMergeSuggestionsForAllTenants(): Promise { - const tenants = await activity.getAllTenants() - const info = workflowInfo() - await Promise.all( - tenants.map((tenant) => { - return startChild(generateOrganizationMergeSuggestions, { - workflowId: `${info.workflowId}/${tenant.tenantId}`, - cancellationType: ChildWorkflowCancellationType.ABANDON, - parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON, - retry: { - backoffCoefficient: 2, - initialInterval: 2 * 1000, - maximumInterval: 30 * 1000, - }, - args: [ - { - tenantId: tenant.tenantId, - }, - ], - searchAttributes: { - TenantId: [tenant.tenantId], - }, - }) - }), - ) -}