feat: workflow run dispatcher
This commit is contained in:
@@ -5,9 +5,9 @@ import {
|
||||
ClockCircleOutlined as ClockCircleOutlinedIcon,
|
||||
CloseCircleOutlined as CloseCircleOutlinedIcon,
|
||||
DeleteOutlined as DeleteOutlinedIcon,
|
||||
PauseCircleOutlined as PauseCircleOutlinedIcon,
|
||||
PauseOutlined as PauseOutlinedIcon,
|
||||
SelectOutlined as SelectOutlinedIcon,
|
||||
StopOutlined as StopOutlinedIcon,
|
||||
SyncOutlined as SyncOutlinedIcon,
|
||||
} from "@ant-design/icons";
|
||||
import { useRequest } from "ahooks";
|
||||
@@ -75,7 +75,7 @@ const WorkflowRuns = ({ className, style, workflowId }: WorkflowRunsProps) => {
|
||||
);
|
||||
} else if (record.status === WORKFLOW_RUN_STATUSES.CANCELED) {
|
||||
return (
|
||||
<Tag icon={<PauseCircleOutlinedIcon />} color="warning">
|
||||
<Tag icon={<StopOutlinedIcon />} color="warning">
|
||||
{t("workflow_run.props.status.canceled")}
|
||||
</Tag>
|
||||
);
|
||||
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
ClockCircleOutlined as ClockCircleOutlinedIcon,
|
||||
CloseCircleOutlined as CloseCircleOutlinedIcon,
|
||||
LockOutlined as LockOutlinedIcon,
|
||||
PauseCircleOutlined as PauseCircleOutlinedIcon,
|
||||
PlusOutlined as PlusOutlinedIcon,
|
||||
SelectOutlined as SelectOutlinedIcon,
|
||||
SendOutlined as SendOutlinedIcon,
|
||||
StopOutlined as StopOutlinedIcon,
|
||||
SyncOutlined as SyncOutlinedIcon,
|
||||
} from "@ant-design/icons";
|
||||
import { PageHeader } from "@ant-design/pro-components";
|
||||
@@ -89,7 +89,6 @@ const Dashboard = () => {
|
||||
const workflow = record.expand?.workflowId;
|
||||
return (
|
||||
<Typography.Link
|
||||
type="secondary"
|
||||
ellipsis
|
||||
onClick={() => {
|
||||
if (workflow) {
|
||||
@@ -129,7 +128,7 @@ const Dashboard = () => {
|
||||
);
|
||||
} else if (record.status === WORKFLOW_RUN_STATUSES.CANCELED) {
|
||||
return (
|
||||
<Tag icon={<PauseCircleOutlinedIcon />} color="warning">
|
||||
<Tag icon={<StopOutlinedIcon />} color="warning">
|
||||
{t("workflow_run.props.status.canceled")}
|
||||
</Tag>
|
||||
);
|
||||
|
||||
@@ -42,7 +42,6 @@ const WorkflowDetail = () => {
|
||||
useZustandShallowSelector(["workflow", "initialized", "init", "destroy", "setEnabled", "release", "discard"])
|
||||
);
|
||||
useEffect(() => {
|
||||
// TODO: loading & error
|
||||
workflowState.init(workflowId!);
|
||||
|
||||
return () => {
|
||||
@@ -52,7 +51,7 @@ const WorkflowDetail = () => {
|
||||
|
||||
const [tabValue, setTabValue] = useState<"orchestration" | "runs">("orchestration");
|
||||
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
const [isPendingOrRunning, setIsPendingOrRunning] = useState(false);
|
||||
const lastRunStatus = useMemo(() => workflow.lastRunStatus, [workflow]);
|
||||
|
||||
const [allowDiscard, setAllowDiscard] = useState(false);
|
||||
@@ -60,14 +59,14 @@ const WorkflowDetail = () => {
|
||||
const [allowRun, setAllowRun] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsRunning(lastRunStatus == WORKFLOW_RUN_STATUSES.PENDING || lastRunStatus == WORKFLOW_RUN_STATUSES.RUNNING);
|
||||
setIsPendingOrRunning(lastRunStatus == WORKFLOW_RUN_STATUSES.PENDING || lastRunStatus == WORKFLOW_RUN_STATUSES.RUNNING);
|
||||
}, [lastRunStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!!workflowId && isRunning) {
|
||||
if (!!workflowId && isPendingOrRunning) {
|
||||
subscribeWorkflow(workflowId, (e) => {
|
||||
if (e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.PENDING && e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.RUNNING) {
|
||||
setIsRunning(false);
|
||||
setIsPendingOrRunning(false);
|
||||
unsubscribeWorkflow(workflowId);
|
||||
}
|
||||
});
|
||||
@@ -76,15 +75,15 @@ const WorkflowDetail = () => {
|
||||
unsubscribeWorkflow(workflowId);
|
||||
};
|
||||
}
|
||||
}, [workflowId, isRunning]);
|
||||
}, [workflowId, isPendingOrRunning]);
|
||||
|
||||
useEffect(() => {
|
||||
const hasReleased = !!workflow.content;
|
||||
const hasChanges = workflow.hasDraft! || !isEqual(workflow.draft, workflow.content);
|
||||
setAllowDiscard(!isRunning && hasReleased && hasChanges);
|
||||
setAllowRelease(!isRunning && hasChanges);
|
||||
setAllowDiscard(!isPendingOrRunning && hasReleased && hasChanges);
|
||||
setAllowRelease(!isPendingOrRunning && hasChanges);
|
||||
setAllowRun(hasReleased);
|
||||
}, [workflow.content, workflow.draft, workflow.hasDraft, isRunning]);
|
||||
}, [workflow.content, workflow.draft, workflow.hasDraft, isPendingOrRunning]);
|
||||
|
||||
const handleEnableChange = async () => {
|
||||
if (!workflow.enabled && (!workflow.content || !isAllNodesValidated(workflow.content))) {
|
||||
@@ -174,12 +173,12 @@ const WorkflowDetail = () => {
|
||||
let unsubscribeFn: Awaited<ReturnType<typeof subscribeWorkflow>> | undefined = undefined;
|
||||
|
||||
try {
|
||||
setIsRunning(true);
|
||||
setIsPendingOrRunning(true);
|
||||
|
||||
// subscribe before running workflow
|
||||
unsubscribeFn = await subscribeWorkflow(workflowId!, (e) => {
|
||||
if (e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.PENDING && e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.RUNNING) {
|
||||
setIsRunning(false);
|
||||
setIsPendingOrRunning(false);
|
||||
unsubscribeFn?.();
|
||||
}
|
||||
});
|
||||
@@ -188,7 +187,7 @@ const WorkflowDetail = () => {
|
||||
|
||||
messageApi.info(t("workflow.detail.orchestration.action.run.prompt"));
|
||||
} catch (err) {
|
||||
setIsRunning(false);
|
||||
setIsPendingOrRunning(false);
|
||||
unsubscribeFn?.();
|
||||
|
||||
console.error(err);
|
||||
@@ -279,7 +278,7 @@ const WorkflowDetail = () => {
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<Space>
|
||||
<Button disabled={!allowRun} icon={<CaretRightOutlinedIcon />} loading={isRunning} type="primary" onClick={handleRunClick}>
|
||||
<Button disabled={!allowRun} icon={<CaretRightOutlinedIcon />} loading={isPendingOrRunning} type="primary" onClick={handleRunClick}>
|
||||
{t("workflow.detail.orchestration.action.run")}
|
||||
</Button>
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
CloseCircleOutlined as CloseCircleOutlinedIcon,
|
||||
DeleteOutlined as DeleteOutlinedIcon,
|
||||
EditOutlined as EditOutlinedIcon,
|
||||
PauseCircleOutlined as PauseCircleOutlinedIcon,
|
||||
PlusOutlined as PlusOutlinedIcon,
|
||||
StopOutlined as StopOutlinedIcon,
|
||||
SyncOutlined as SyncOutlinedIcon,
|
||||
} from "@ant-design/icons";
|
||||
|
||||
@@ -170,7 +170,7 @@ const WorkflowList = () => {
|
||||
} else if (record.lastRunStatus === WORKFLOW_RUN_STATUSES.FAILED) {
|
||||
icon = <CloseCircleOutlinedIcon style={{ color: themeToken.colorError }} />;
|
||||
} else if (record.lastRunStatus === WORKFLOW_RUN_STATUSES.CANCELED) {
|
||||
icon = <PauseCircleOutlinedIcon style={{ color: themeToken.colorWarning }} />;
|
||||
icon = <StopOutlinedIcon style={{ color: themeToken.colorWarning }} />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user