feat: Implement CancelSubProcess action, fix process execution flow. (#10530)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2026-02-20 10:23:03 +07:00
committed by GitHub
parent f446e036ee
commit bb6d4c74e9
28 changed files with 202 additions and 41 deletions
@@ -126,7 +126,7 @@ export async function CheckSubProcessMatch (
)
if (predicate === '$all') {
return res.length === subExecutions.length
} else if (predicate === '$any') {
} else if (predicate === '$in') {
return res.length > 0
} else if (predicate === '$nin') {
return res.length === 0
@@ -337,6 +337,38 @@ export async function AddTag (
}
}
export async function CancelSubProcess (
params: MethodParams<Execution>,
execution: Execution,
control: ProcessControl
): Promise<ExecuteResult> {
const processId = params._id as Ref<Process>
if (processId === undefined) throw processError(process.error.RequiredParamsNotProvided, { params: '_id' })
const target = control.client.getModel().findObject(processId)
if (target === undefined) throw processError(process.error.ObjectNotFound, { _id: processId })
const res: Tx[] = []
const rollback: Tx[] = []
const executions = await control.client.findAll(process.class.Execution, {
card: execution.card,
process: processId,
status: ExecutionStatus.Active
})
for (const exec of executions) {
res.push(
control.client.txFactory.createTxUpdateDoc(process.class.Execution, execution.space, exec._id, {
status: ExecutionStatus.Cancelled
})
)
rollback.push(
control.client.txFactory.createTxUpdateDoc(process.class.Execution, execution.space, exec._id, {
status: ExecutionStatus.Active
})
)
}
return { txes: res, rollback, context: null }
}
export async function RunSubProcess (
params: MethodParams<Execution>,
execution: Execution,
@@ -611,7 +643,7 @@ export async function CancelToDo (
): Promise<ExecuteResult> {
if (params._id === undefined) throw processError(process.error.RequiredParamsNotProvided, { params: '_id' })
const todo = await control.client.findOne(process.class.ProcessToDo, { _id: params._id as any })
if (todo === undefined) throw processError(process.error.ObjectNotFound, { _id: params._id })
if (todo === undefined) return { txes: [], rollback: [], context: null }
if (todo.doneOn !== null) throw processError(process.error.ToDoAlreadyCompleted, { _id: params._id })
const res: Tx[] = [control.client.txFactory.createTxRemoveDoc(todo._class, todo.space, todo._id)]
const rollback: Tx[] = [
@@ -89,6 +89,7 @@ import {
} from './transform'
import {
RunSubProcess,
CancelSubProcess,
CreateToDo,
UpdateCard,
CreateCard,
@@ -489,6 +490,7 @@ export * from './utils'
export default async () => ({
func: {
RunSubProcess,
CancelSubProcess,
CreateToDo,
UpdateCard,
CreateCard,