mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-19 01:41:55 +08:00
refactor: clean code
This commit is contained in:
parent
e4e0a24a06
commit
8ed2b2475c
@ -65,6 +65,9 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context, certPem string, privkeyP
|
||||
if d.config.SecretName == "" {
|
||||
return nil, errors.New("config `secretName` is required")
|
||||
}
|
||||
if d.config.SecretType == "" {
|
||||
return nil, errors.New("config `secretType` is required")
|
||||
}
|
||||
if d.config.SecretDataKeyForCrt == "" {
|
||||
return nil, errors.New("config `secretDataKeyForCrt` is required")
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import type { RecordModel, RecordSubscription } from "pocketbase";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
import { ClientResponseError, type RecordSubscription } from "pocketbase";
|
||||
|
||||
import { WORKFLOW_TRIGGERS } from "@/domain/workflow";
|
||||
import { WORKFLOW_TRIGGERS, type WorkflowModel } from "@/domain/workflow";
|
||||
import { getPocketBase } from "@/repository/pocketbase";
|
||||
|
||||
export const run = async (id: string) => {
|
||||
@ -25,14 +24,14 @@ export const run = async (id: string) => {
|
||||
return resp;
|
||||
};
|
||||
|
||||
export const subscribe = async (id: string, cb: (e: RecordSubscription<RecordModel>) => void) => {
|
||||
export const subscribe = async (id: string, cb: (e: RecordSubscription<WorkflowModel>) => void) => {
|
||||
const pb = getPocketBase();
|
||||
|
||||
pb.collection("workflow").subscribe(id, cb);
|
||||
return pb.collection("workflow").subscribe(id, cb);
|
||||
};
|
||||
|
||||
export const unsubscribe = async (id: string) => {
|
||||
const pb = getPocketBase();
|
||||
|
||||
pb.collection("workflow").unsubscribe(id);
|
||||
return pb.collection("workflow").unsubscribe(id);
|
||||
};
|
||||
|
@ -18,11 +18,11 @@ export type UseZustandShallowSelectorReturns<T extends object, TKeys extends key
|
||||
* const { foo, bar, baz } = useStore(useZustandShallowSelector(["foo", "bar", "baz"]));
|
||||
*
|
||||
* // 以上代码等效于:
|
||||
* const { foo, bar, baz } = useStore((state) => ({
|
||||
* const { foo, bar, baz } = useStore(useShallow((state) => ({
|
||||
* foo: state.foo,
|
||||
* bar: state.bar,
|
||||
* baz: state.baz,
|
||||
* }));
|
||||
* })));
|
||||
* ```
|
||||
*/
|
||||
const useZustandShallowSelector = <T extends object, TKeys extends keyof T>(paths: MaybeMany<TKeys>): UseZustandShallowSelectorReturns<T, TKeys> => {
|
||||
|
@ -13,16 +13,16 @@ import {
|
||||
import { PageHeader } from "@ant-design/pro-components";
|
||||
import { Alert, Button, Card, Dropdown, Form, Input, Modal, Space, Tabs, Typography, message, notification } from "antd";
|
||||
import { createSchemaFieldRule } from "antd-zod";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
import { isEqual } from "radash";
|
||||
import { z } from "zod";
|
||||
|
||||
import { run as runWorkflow, subscribe, unsubscribe } from "@/api/workflow";
|
||||
import { run as runWorkflow, subscribe as subscribeWorkflow, unsubscribe as unsubscribeWorkflow } from "@/api/workflow";
|
||||
import ModalForm from "@/components/ModalForm";
|
||||
import Show from "@/components/Show";
|
||||
import WorkflowElements from "@/components/workflow/WorkflowElements";
|
||||
import WorkflowRuns from "@/components/workflow/WorkflowRuns";
|
||||
import { isAllNodesValidated } from "@/domain/workflow";
|
||||
import { WORKFLOW_RUN_STATUSES } from "@/domain/workflowRun";
|
||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||
import { remove as removeWorkflow } from "@/repository/workflow";
|
||||
import { useWorkflowStore } from "@/stores/workflow";
|
||||
@ -63,21 +63,21 @@ const WorkflowDetail = () => {
|
||||
}, [workflow]);
|
||||
|
||||
useEffect(() => {
|
||||
if (lastRunStatus && lastRunStatus == "running") {
|
||||
setIsRunning(true);
|
||||
} else {
|
||||
setIsRunning(false);
|
||||
}
|
||||
setIsRunning(lastRunStatus == WORKFLOW_RUN_STATUSES.RUNNING);
|
||||
}, [lastRunStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isRunning && workflowId) {
|
||||
subscribe(workflowId, (e) => {
|
||||
if (e.record.lastRunStatus !== "running") {
|
||||
if (!!workflowId && isRunning) {
|
||||
subscribeWorkflow(workflowId, (e) => {
|
||||
if (e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.RUNNING) {
|
||||
setIsRunning(false);
|
||||
unsubscribe(workflowId);
|
||||
unsubscribeWorkflow(workflowId);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribeWorkflow(workflowId);
|
||||
};
|
||||
}
|
||||
}, [workflowId, isRunning]);
|
||||
|
||||
@ -174,26 +174,28 @@ const WorkflowDetail = () => {
|
||||
}
|
||||
|
||||
promise.then(async () => {
|
||||
let unsubscribeFn: Awaited<ReturnType<typeof subscribeWorkflow>> | undefined = undefined;
|
||||
|
||||
try {
|
||||
setIsRunning(true);
|
||||
|
||||
// subscribe before running workflow
|
||||
subscribe(workflowId!, (e) => {
|
||||
if (e.record.lastRunStatus !== "running") {
|
||||
unsubscribeFn = await subscribeWorkflow(workflowId!, (e) => {
|
||||
if (e.record.lastRunStatus !== WORKFLOW_RUN_STATUSES.RUNNING) {
|
||||
setIsRunning(false);
|
||||
unsubscribe(workflowId!);
|
||||
unsubscribeFn?.();
|
||||
}
|
||||
});
|
||||
|
||||
await runWorkflow(workflowId!);
|
||||
|
||||
setIsRunning(true);
|
||||
messageApi.success(t("common.text.operation_succeeded"));
|
||||
} catch (err) {
|
||||
if (err instanceof ClientResponseError && err.isAbort) {
|
||||
return;
|
||||
}
|
||||
setIsRunning(false);
|
||||
unsubscribeFn?.();
|
||||
|
||||
console.error(err);
|
||||
messageApi.warning(t("common.text.operation_failed"));
|
||||
setIsRunning(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user