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

Function archiveWorkflow

apps/sim/lib/workflows/lifecycle.ts:88–207  ·  view source on GitHub ↗
(
  workflowId: string,
  options: ArchiveWorkflowOptions
)

Source from the content-addressed store, hash-verified

86}
87
88export async function archiveWorkflow(
89 workflowId: string,
90 options: ArchiveWorkflowOptions
91): Promise<{ archived: boolean; workflow: Awaited<ReturnType<typeof getWorkflowById>> | null }> {
92 const existingWorkflow = await getWorkflowById(workflowId, { includeArchived: true })
93
94 if (!existingWorkflow) {
95 return { archived: false, workflow: null }
96 }
97
98 if (existingWorkflow.archivedAt) {
99 return { archived: false, workflow: existingWorkflow }
100 }
101
102 const now = options.archivedAt ?? new Date()
103 const affectedWorkflowMcpServers = await db
104 .select({ serverId: workflowMcpTool.serverId })
105 .from(workflowMcpTool)
106 .where(and(eq(workflowMcpTool.workflowId, workflowId), isNull(workflowMcpTool.archivedAt)))
107
108 await db.transaction(async (tx) => {
109 await tx
110 .update(workflowSchedule)
111 .set({
112 archivedAt: now,
113 updatedAt: now,
114 status: 'disabled',
115 nextRunAt: null,
116 lastQueuedAt: null,
117 })
118 .where(and(eq(workflowSchedule.workflowId, workflowId), isNull(workflowSchedule.archivedAt)))
119
120 await tx
121 .update(webhook)
122 .set({
123 archivedAt: now,
124 updatedAt: now,
125 isActive: false,
126 })
127 .where(and(eq(webhook.workflowId, workflowId), isNull(webhook.archivedAt)))
128
129 await tx
130 .update(chat)
131 .set({
132 archivedAt: now,
133 updatedAt: now,
134 isActive: false,
135 })
136 .where(and(eq(chat.workflowId, workflowId), isNull(chat.archivedAt)))
137
138 await tx
139 .update(workflowMcpTool)
140 .set({
141 archivedAt: now,
142 updatedAt: now,
143 })
144 .where(and(eq(workflowMcpTool.workflowId, workflowId), isNull(workflowMcpTool.archivedAt)))
145

Callers 4

lifecycle.test.tsFile · 0.90
performDeleteWorkflowFunction · 0.90
deleteWorkflowRecordFunction · 0.85
archiveWorkflowsFunction · 0.85

Calls 8

getWorkflowByIdFunction · 0.90
notifyWorkflowArchivedFunction · 0.85
setMethod · 0.65
warnMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected