Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
fa106eb2
authored
Aug 24, 2024
by
Archer
Committed by
GitHub
Aug 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: dispatch workflow skip status (#2496)
parent
3248e95d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
54 deletions
+65
-54
packages/service/core/workflow/dispatch/index.ts
+65
-54
No files found.
packages/service/core/workflow/dispatch/index.ts
View file @
fa106eb2
...
@@ -275,66 +275,77 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
...
@@ -275,66 +275,77 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
};
};
}
}
async
function
checkNodeCanRun
(
node
:
RuntimeNodeItemType
):
Promise
<
any
>
{
// 每个节点 运行/跳过 后,初始化边的状态
const
status
=
checkNodeRunStatus
({
function
nodeRunAfterHook
(
node
:
RuntimeNodeItemType
)
{
node
,
node
.
isEntry
=
false
;
runtimeEdges
});
if
(
res
?.
closed
||
props
.
maxRunTimes
<=
0
)
return
;
runtimeEdges
.
forEach
((
item
)
=>
{
props
.
maxRunTimes
--
;
if
(
item
.
target
===
node
.
nodeId
)
{
addLog
.
debug
(
`Run node`
,
{
maxRunTimes
:
props
.
maxRunTimes
,
uid
:
user
.
_id
});
item
.
status
=
'waiting'
;
}
});
}
/* Check node run/skip or wait */
function
checkNodeCanRun
(
nodes
:
RuntimeNodeItemType
[]
=
[]):
Promise
<
any
>
{
return
Promise
.
all
(
nodes
.
map
(
async
(
node
)
=>
{
const
status
=
checkNodeRunStatus
({
node
,
runtimeEdges
});
await
surrenderProcess
()
;
if
(
res
?.
closed
||
props
.
maxRunTimes
<=
0
)
return
;
const
response
:
addLog
.
debug
(
`Run node`
,
{
maxRunTimes
:
props
.
maxRunTimes
,
uid
:
user
.
_id
});
|
{
node
:
RuntimeNodeItemType
;
result
:
Record
<
string
,
any
>
;
}
|
undefined
=
await
(()
=>
{
if
(
status
===
'run'
)
{
addLog
.
debug
(
`[dispatchWorkFlow] nodeRunWithActive:
${
node
.
name
}
`
);
return
nodeRunWithActive
(
node
);
}
if
(
status
===
'skip'
)
{
addLog
.
debug
(
`[dispatchWorkFlow] nodeRunWithSkip:
${
node
.
name
}
`
);
return
nodeRunWithSkip
(
node
);
}
})();
if
(
!
response
)
return
;
// Thread avoidance
await
surrenderProcess
();
// Update the node output at the end of the run and get the next nodes
if
(
status
===
'run'
)
{
const
nextNodes
=
nodeOutput
(
response
.
node
,
response
.
result
);
addLog
.
debug
(
`[dispatchWorkFlow] nodeRunWithActive:
${
node
.
name
}
`
);
// Remove repeat nodes(Make sure that the node is only executed once)
return
nodeRunWithActive
(
node
);
const
filterNextNodes
=
nextNodes
.
filter
(
}
(
node
,
index
,
self
)
=>
self
.
findIndex
((
t
)
=>
t
.
nodeId
===
node
.
nodeId
)
===
index
if
(
status
===
'skip'
)
{
);
addLog
.
debug
(
`[dispatchWorkFlow] nodeRunWithSkip:
${
node
.
name
}
`
);
return
nodeRunWithSkip
(
node
);
}
// In the current version, only one interactive node is allowed at the same time
return
;
const
interactiveResponse
:
UserInteractiveType
|
undefined
=
})
response
.
result
?.[
DispatchNodeResponseKeyEnum
.
interactive
];
).
then
((
result
)
=>
{
if
(
interactiveResponse
)
{
props
.
maxRunTimes
--
;
chatAssistantResponse
.
push
(
handleInteractiveResult
({
const
flat
=
result
.
flat
().
filter
(
Boolean
)
as
unknown
as
{
entryNodeIds
:
[
response
.
node
.
nodeId
],
node
:
RuntimeNodeItemType
;
interactiveResponse
result
:
Record
<
string
,
any
>
;
})
}[];
if
(
flat
.
length
===
0
)
return
;
// Update the node output at the end of the run and get the next nodes
const
nextNodes
=
flat
.
map
((
item
)
=>
nodeOutput
(
item
.
node
,
item
.
result
)).
flat
();
// Remove repeat nodes(Make sure that the node is only executed once)
const
filterNextNodes
=
nextNodes
.
filter
(
(
node
,
index
,
self
)
=>
self
.
findIndex
((
t
)
=>
t
.
nodeId
===
node
.
nodeId
)
===
index
);
);
return
;
}
return
Promise
.
all
(
filterNextNodes
.
map
(
checkNodeCanRun
));
// In the current version, only one interactive node is allowed at the same time
}
const
haveInteractiveResponse
=
flat
// 运行完一轮后,清除连线的状态,避免污染进程
.
map
((
response
)
=>
{
function
nodeRunFinish
(
node
:
RuntimeNodeItemType
)
{
const
interactiveResponse
=
response
.
result
?.[
DispatchNodeResponseKeyEnum
.
interactive
];
node
.
isEntry
=
false
;
if
(
interactiveResponse
)
{
chatAssistantResponse
.
push
(
handleInteractiveResult
({
entryNodeIds
:
[
response
.
node
.
nodeId
],
interactiveResponse
})
);
return
1
;
}
})
.
filter
(
Boolean
);
if
(
haveInteractiveResponse
.
length
>
0
)
return
;
runtimeEdges
.
forEach
((
item
)
=>
{
return
checkNodeCanRun
(
filterNextNodes
);
if
(
item
.
target
===
node
.
nodeId
)
{
item
.
status
=
'waiting'
;
}
});
});
}
}
/* Inject data into module input */
/* Inject data into module input */
...
@@ -444,7 +455,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
...
@@ -444,7 +455,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
dispatchRes
[
item
.
key
]
=
valueTypeFormat
(
item
.
defaultValue
,
item
.
valueType
);
dispatchRes
[
item
.
key
]
=
valueTypeFormat
(
item
.
defaultValue
,
item
.
valueType
);
});
});
nodeRun
Finish
(
node
);
nodeRun
AfterHook
(
node
);
return
{
return
{
node
,
node
,
...
@@ -457,7 +468,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
...
@@ -457,7 +468,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
async
function
nodeRunWithSkip
(
node
:
RuntimeNodeItemType
)
{
async
function
nodeRunWithSkip
(
node
:
RuntimeNodeItemType
)
{
// 其后所有target的节点,都设置为skip
// 其后所有target的节点,都设置为skip
const
targetEdges
=
runtimeEdges
.
filter
((
item
)
=>
item
.
source
===
node
.
nodeId
);
const
targetEdges
=
runtimeEdges
.
filter
((
item
)
=>
item
.
source
===
node
.
nodeId
);
nodeRun
Finish
(
node
);
nodeRun
AfterHook
(
node
);
return
{
return
{
node
,
node
,
...
@@ -474,7 +485,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
...
@@ -474,7 +485,7 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
// runtimeNodes.forEach((item) => {
// runtimeNodes.forEach((item) => {
// item.isEntry = false;
// item.isEntry = false;
// });
// });
await
Promise
.
all
(
entryNodes
.
map
(
checkNodeCanRun
)
);
await
checkNodeCanRun
(
entryNodes
);
// focus try to run pluginOutput
// focus try to run pluginOutput
const
pluginOutputModule
=
runtimeNodes
.
find
(
const
pluginOutputModule
=
runtimeNodes
.
find
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment