MCPcopy Index your code
hub / github.com/simstudioai/sim / activateWorkflowVersion

Function activateWorkflowVersion

apps/sim/lib/workflows/persistence/utils.ts:995–1099  ·  view source on GitHub ↗
(params: {
  workflowId: string
  version: number
  onActivateTransaction?: (
    tx: DbOrTx,
    result: { deploymentVersionId: string; previousVersionId?: string }
  ) => Promise<void>
})

Source from the content-addressed store, hash-verified

993}
994
995export async function activateWorkflowVersion(params: {
996 workflowId: string
997 version: number
998 onActivateTransaction?: (
999 tx: DbOrTx,
1000 result: { deploymentVersionId: string; previousVersionId?: string }
1001 ) => Promise<void>
1002}): Promise<{
1003 success: boolean
1004 deployedAt?: Date
1005 state?: unknown
1006 previousVersionId?: string
1007 error?: string
1008}> {
1009 const { workflowId, version } = params
1010
1011 try {
1012 const now = new Date()
1013 let versionState: unknown
1014
1015 const result = await db.transaction(async (tx) => {
1016 if (!(await lockWorkflowForUpdate(tx, workflowId))) {
1017 return { success: false as const, error: 'Workflow not found' }
1018 }
1019
1020 const [currentActiveVersion] = await tx
1021 .select({ id: workflowDeploymentVersion.id })
1022 .from(workflowDeploymentVersion)
1023 .where(
1024 and(
1025 eq(workflowDeploymentVersion.workflowId, workflowId),
1026 eq(workflowDeploymentVersion.isActive, true)
1027 )
1028 )
1029 .limit(1)
1030
1031 const [versionData] = await tx
1032 .select({ id: workflowDeploymentVersion.id, state: workflowDeploymentVersion.state })
1033 .from(workflowDeploymentVersion)
1034 .where(
1035 and(
1036 eq(workflowDeploymentVersion.workflowId, workflowId),
1037 eq(workflowDeploymentVersion.version, version)
1038 )
1039 )
1040 .limit(1)
1041
1042 if (!versionData) {
1043 return { success: false as const, error: 'Deployment version not found' }
1044 }
1045 versionState = versionData.state
1046
1047 await tx
1048 .update(workflowDeploymentVersion)
1049 .set({ isActive: false })
1050 .where(
1051 and(
1052 eq(workflowDeploymentVersion.workflowId, workflowId),

Callers 1

performActivateVersionFunction · 0.90

Calls 6

getErrorMessageFunction · 0.90
lockWorkflowForUpdateFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
setMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected