mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
feat: rename , executionMethod
/type
to trigger
, crontab
to triggerCron
This commit is contained in:
parent
2213399f5e
commit
da76d1065e
@ -15,19 +15,19 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WorkflowTypeAuto = "auto"
|
WorkflowTriggerAuto = "auto"
|
||||||
WorkflowTypeManual = "manual"
|
WorkflowTriggerManual = "manual"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Workflow struct {
|
type Workflow struct {
|
||||||
Meta
|
Meta
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Type string `json:"type"`
|
Trigger string `json:"trigger"`
|
||||||
Crontab string `json:"crontab"`
|
TriggerCron string `json:"triggerCron"`
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
Content *WorkflowNode `json:"content"`
|
Content *WorkflowNode `json:"content"`
|
||||||
Draft *WorkflowNode `json:"draft"`
|
Draft *WorkflowNode `json:"draft"`
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
HasDraft bool `json:"hasDraft"`
|
HasDraft bool `json:"hasDraft"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ func NewWorkflowRepository() *WorkflowRepository {
|
|||||||
func (w *WorkflowRepository) ListEnabledAuto(ctx context.Context) ([]domain.Workflow, error) {
|
func (w *WorkflowRepository) ListEnabledAuto(ctx context.Context) ([]domain.Workflow, error) {
|
||||||
records, err := app.GetApp().Dao().FindRecordsByFilter(
|
records, err := app.GetApp().Dao().FindRecordsByFilter(
|
||||||
"workflow",
|
"workflow",
|
||||||
"enabled={:enabled} && type={:type}",
|
"enabled={:enabled} && trigger={:trigger}",
|
||||||
"-created", 1000, 0, dbx.Params{"enabled": true, "type": domain.WorkflowTypeAuto},
|
"-created", 1000, 0, dbx.Params{"enabled": true, "trigger": domain.WorkflowTriggerAuto},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -83,13 +83,12 @@ func record2Workflow(record *models.Record) (*domain.Workflow, error) {
|
|||||||
},
|
},
|
||||||
Name: record.GetString("name"),
|
Name: record.GetString("name"),
|
||||||
Description: record.GetString("description"),
|
Description: record.GetString("description"),
|
||||||
Type: record.GetString("type"),
|
Trigger: record.GetString("trigger"),
|
||||||
Crontab: record.GetString("crontab"),
|
TriggerCron: record.GetString("triggerCron"),
|
||||||
Enabled: record.GetBool("enabled"),
|
Enabled: record.GetBool("enabled"),
|
||||||
|
Content: content,
|
||||||
|
Draft: draft,
|
||||||
HasDraft: record.GetBool("hasDraft"),
|
HasDraft: record.GetBool("hasDraft"),
|
||||||
|
|
||||||
Content: content,
|
|
||||||
Draft: draft,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return workflow, nil
|
return workflow, nil
|
||||||
|
@ -46,16 +46,16 @@ func update(ctx context.Context, record *models.Record) error {
|
|||||||
|
|
||||||
id := record.Id
|
id := record.Id
|
||||||
enabled := record.GetBool("enabled")
|
enabled := record.GetBool("enabled")
|
||||||
executeMethod := record.GetString("type")
|
trigger := record.GetString("trigger")
|
||||||
|
|
||||||
scheduler := app.GetScheduler()
|
scheduler := app.GetScheduler()
|
||||||
if !enabled || executeMethod == domain.WorkflowTypeManual {
|
if !enabled || trigger == domain.WorkflowTriggerManual {
|
||||||
scheduler.Remove(id)
|
scheduler.Remove(id)
|
||||||
scheduler.Start()
|
scheduler.Start()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := scheduler.Add(id, record.GetString("crontab"), func() {
|
err := scheduler.Add(id, record.GetString("triggerCron"), func() {
|
||||||
NewWorkflowService(repository.NewWorkflowRepository()).Run(ctx, &domain.WorkflowRunReq{
|
NewWorkflowService(repository.NewWorkflowRepository()).Run(ctx, &domain.WorkflowRunReq{
|
||||||
Id: id,
|
Id: id,
|
||||||
})
|
})
|
||||||
|
@ -33,7 +33,7 @@ func (s *WorkflowService) InitSchedule(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
scheduler := app.GetScheduler()
|
scheduler := app.GetScheduler()
|
||||||
for _, workflow := range workflows {
|
for _, workflow := range workflows {
|
||||||
err := scheduler.Add(workflow.Id, workflow.Crontab, func() {
|
err := scheduler.Add(workflow.Id, workflow.TriggerCron, func() {
|
||||||
s.Run(ctx, &domain.WorkflowRunReq{
|
s.Run(ctx, &domain.WorkflowRunReq{
|
||||||
Id: workflow.Id,
|
Id: workflow.Id,
|
||||||
})
|
})
|
||||||
|
116
migrations/1735966817_updated_workflow.go
Normal file
116
migrations/1735966817_updated_workflow.go
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
"github.com/pocketbase/pocketbase/models/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("tovyif5ax6j62ur")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// update
|
||||||
|
edit_trigger := &schema.SchemaField{}
|
||||||
|
if err := json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "vqoajwjq",
|
||||||
|
"name": "trigger",
|
||||||
|
"type": "select",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSelect": 1,
|
||||||
|
"values": [
|
||||||
|
"auto",
|
||||||
|
"manual"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}`), edit_trigger); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
collection.Schema.AddField(edit_trigger)
|
||||||
|
|
||||||
|
// update
|
||||||
|
edit_triggerCron := &schema.SchemaField{}
|
||||||
|
if err := json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "8ho247wh",
|
||||||
|
"name": "triggerCron",
|
||||||
|
"type": "text",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"min": null,
|
||||||
|
"max": null,
|
||||||
|
"pattern": ""
|
||||||
|
}
|
||||||
|
}`), edit_triggerCron); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
collection.Schema.AddField(edit_triggerCron)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("tovyif5ax6j62ur")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// update
|
||||||
|
edit_trigger := &schema.SchemaField{}
|
||||||
|
if err := json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "vqoajwjq",
|
||||||
|
"name": "type",
|
||||||
|
"type": "select",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSelect": 1,
|
||||||
|
"values": [
|
||||||
|
"auto",
|
||||||
|
"manual"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}`), edit_trigger); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
collection.Schema.AddField(edit_trigger)
|
||||||
|
|
||||||
|
// update
|
||||||
|
edit_triggerCron := &schema.SchemaField{}
|
||||||
|
if err := json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "8ho247wh",
|
||||||
|
"name": "crontab",
|
||||||
|
"type": "text",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"min": null,
|
||||||
|
"max": null,
|
||||||
|
"pattern": ""
|
||||||
|
}
|
||||||
|
}`), edit_triggerCron); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
collection.Schema.AddField(edit_triggerCron)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
@ -6,7 +6,7 @@ import { produce } from "immer";
|
|||||||
import Show from "@/components/Show";
|
import Show from "@/components/Show";
|
||||||
import { deployProvidersMap } from "@/domain/provider";
|
import { deployProvidersMap } from "@/domain/provider";
|
||||||
import { notifyChannelsMap } from "@/domain/settings";
|
import { notifyChannelsMap } from "@/domain/settings";
|
||||||
import { type WorkflowNode, WorkflowNodeType } from "@/domain/workflow";
|
import { WORKFLOW_TRIGGERS, type WorkflowNode, WorkflowNodeType } from "@/domain/workflow";
|
||||||
import { useZustandShallowSelector } from "@/hooks";
|
import { useZustandShallowSelector } from "@/hooks";
|
||||||
import { useWorkflowStore } from "@/stores/workflow";
|
import { useWorkflowStore } from "@/stores/workflow";
|
||||||
|
|
||||||
@ -35,21 +35,21 @@ const WorkflowElement = ({ node, disabled }: NodeProps) => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-between space-x-2">
|
<div className="flex items-center justify-between space-x-2">
|
||||||
<Typography.Text className="truncate">
|
<Typography.Text className="truncate">
|
||||||
{node.config?.executionMethod === "auto"
|
{node.config?.trigger === WORKFLOW_TRIGGERS.AUTO
|
||||||
? t("workflow.props.trigger.auto")
|
? t("workflow.props.trigger.auto")
|
||||||
: node.config?.executionMethod === "manual"
|
: node.config?.trigger === WORKFLOW_TRIGGERS.MANUAL
|
||||||
? t("workflow.props.trigger.manual")
|
? t("workflow.props.trigger.manual")
|
||||||
: ""}
|
: " "}
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
<Typography.Text className="truncate" type="secondary">
|
<Typography.Text className="truncate" type="secondary">
|
||||||
{node.config?.executionMethod === "auto" ? (node.config?.crontab as string) : ""}
|
{node.config?.trigger === WORKFLOW_TRIGGERS.AUTO ? (node.config?.triggerCron as string) : ""}
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case WorkflowNodeType.Apply: {
|
case WorkflowNodeType.Apply: {
|
||||||
return <Typography.Text className="truncate">{node.config?.domain as string}</Typography.Text>;
|
return <Typography.Text className="truncate">{(node.config?.domain as string) || " "}</Typography.Text>;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WorkflowNodeType.Deploy: {
|
case WorkflowNodeType.Deploy: {
|
||||||
@ -57,7 +57,7 @@ const WorkflowElement = ({ node, disabled }: NodeProps) => {
|
|||||||
return (
|
return (
|
||||||
<Space>
|
<Space>
|
||||||
<Avatar src={provider?.icon} size="small" />
|
<Avatar src={provider?.icon} size="small" />
|
||||||
<Typography.Text className="truncate">{t(provider?.name ?? "")}</Typography.Text>
|
<Typography.Text className="truncate">{t(provider?.name ?? " ")}</Typography.Text>
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ const WorkflowElement = ({ node, disabled }: NodeProps) => {
|
|||||||
const channel = notifyChannelsMap.get(node.config?.channel as string);
|
const channel = notifyChannelsMap.get(node.config?.channel as string);
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-between space-x-2">
|
<div className="flex items-center justify-between space-x-2">
|
||||||
<Typography.Text className="truncate">{t(channel?.name ?? "")}</Typography.Text>
|
<Typography.Text className="truncate">{t(channel?.name ?? " ")}</Typography.Text>
|
||||||
<Typography.Text className="truncate" type="secondary">
|
<Typography.Text className="truncate" type="secondary">
|
||||||
{(node.config?.subject as string) ?? ""}
|
{(node.config?.subject as string) ?? ""}
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
@ -32,7 +32,7 @@ const AddNode = ({ node, disabled }: AddNodeProps) => {
|
|||||||
].map(([type, label, icon]) => {
|
].map(([type, label, icon]) => {
|
||||||
return {
|
return {
|
||||||
key: type as string,
|
key: type as string,
|
||||||
disabled: true,
|
disabled: disabled,
|
||||||
label: t(label as string),
|
label: t(label as string),
|
||||||
icon: icon,
|
icon: icon,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
|
@ -7,7 +7,7 @@ import { produce } from "immer";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import Show from "@/components/Show";
|
import Show from "@/components/Show";
|
||||||
import { type WorkflowNode, type WorkflowStartNodeConfig } from "@/domain/workflow";
|
import { WORKFLOW_TRIGGERS, type WorkflowNode, type WorkflowStartNodeConfig } from "@/domain/workflow";
|
||||||
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
import { useAntdForm, useZustandShallowSelector } from "@/hooks";
|
||||||
import { useWorkflowStore } from "@/stores/workflow";
|
import { useWorkflowStore } from "@/stores/workflow";
|
||||||
import { getNextCronExecutions, validCronExpression } from "@/utils/cron";
|
import { getNextCronExecutions, validCronExpression } from "@/utils/cron";
|
||||||
@ -19,8 +19,8 @@ export type StartNodeFormProps = {
|
|||||||
|
|
||||||
const initFormModel = (): WorkflowStartNodeConfig => {
|
const initFormModel = (): WorkflowStartNodeConfig => {
|
||||||
return {
|
return {
|
||||||
executionMethod: "auto",
|
trigger: WORKFLOW_TRIGGERS.AUTO,
|
||||||
crontab: "0 0 * * *",
|
triggerCron: "0 0 * * *",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,19 +32,19 @@ const StartNodeForm = ({ node }: StartNodeFormProps) => {
|
|||||||
|
|
||||||
const formSchema = z
|
const formSchema = z
|
||||||
.object({
|
.object({
|
||||||
executionMethod: z.string({ message: t("workflow_node.start.form.trigger.placeholder") }).min(1, t("workflow_node.start.form.trigger.placeholder")),
|
trigger: z.string({ message: t("workflow_node.start.form.trigger.placeholder") }).min(1, t("workflow_node.start.form.trigger.placeholder")),
|
||||||
crontab: z.string().nullish(),
|
triggerCron: z.string().nullish(),
|
||||||
})
|
})
|
||||||
.superRefine((data, ctx) => {
|
.superRefine((data, ctx) => {
|
||||||
if (data.executionMethod !== "auto") {
|
if (data.trigger !== WORKFLOW_TRIGGERS.AUTO) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validCronExpression(data.crontab!)) {
|
if (!validCronExpression(data.triggerCron!)) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: t("workflow_node.start.form.trigger_cron.errmsg.invalid"),
|
message: t("workflow_node.start.form.trigger_cron.errmsg.invalid"),
|
||||||
path: ["crontab"],
|
path: ["triggerCron"],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -67,51 +67,45 @@ const StartNodeForm = ({ node }: StartNodeFormProps) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [triggerType, setTriggerType] = useState(node?.config?.executionMethod);
|
const fieldTrigger = Form.useWatch<string>("trigger", formInst);
|
||||||
const [triggerCronLastExecutions, setTriggerCronExecutions] = useState<Date[]>([]);
|
const fieldTriggerCron = Form.useWatch<string>("triggerCron", formInst);
|
||||||
|
const [fieldTriggerCronExpectedExecutions, setFieldTriggerCronExpectedExecutions] = useState<Date[]>([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTriggerType(node?.config?.executionMethod);
|
setFieldTriggerCronExpectedExecutions(getNextCronExecutions(fieldTriggerCron, 5));
|
||||||
setTriggerCronExecutions(getNextCronExecutions(node?.config?.crontab as string, 5));
|
}, [fieldTriggerCron]);
|
||||||
}, [node?.config?.executionMethod, node?.config?.crontab]);
|
|
||||||
|
|
||||||
const handleTriggerTypeChange = (value: string) => {
|
const handleTriggerChange = (value: string) => {
|
||||||
setTriggerType(value);
|
if (value === WORKFLOW_TRIGGERS.AUTO) {
|
||||||
|
formInst.setFieldValue("triggerCron", formInst.getFieldValue("triggerCron") || initFormModel().triggerCron);
|
||||||
if (value === "auto") {
|
|
||||||
formInst.setFieldValue("crontab", formInst.getFieldValue("crontab") || initFormModel().crontab);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTriggerCronChange = (value: string) => {
|
|
||||||
setTriggerCronExecutions(getNextCronExecutions(value, 5));
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...formProps} form={formInst} disabled={formPending} layout="vertical">
|
<Form {...formProps} form={formInst} disabled={formPending} layout="vertical">
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="executionMethod"
|
name="trigger"
|
||||||
label={t("workflow_node.start.form.trigger.label")}
|
label={t("workflow_node.start.form.trigger.label")}
|
||||||
rules={[formRule]}
|
rules={[formRule]}
|
||||||
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.start.form.trigger.tooltip") }}></span>}
|
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.start.form.trigger.tooltip") }}></span>}
|
||||||
>
|
>
|
||||||
<Radio.Group value={triggerType} onChange={(e) => handleTriggerTypeChange(e.target.value)}>
|
<Radio.Group onChange={(e) => handleTriggerChange(e.target.value)}>
|
||||||
<Radio value="auto">{t("workflow_node.start.form.trigger.option.auto.label")}</Radio>
|
<Radio value={WORKFLOW_TRIGGERS.AUTO}>{t("workflow_node.start.form.trigger.option.auto.label")}</Radio>
|
||||||
<Radio value="manual">{t("workflow_node.start.form.trigger.option.manual.label")}</Radio>
|
<Radio value={WORKFLOW_TRIGGERS.MANUAL}>{t("workflow_node.start.form.trigger.option.manual.label")}</Radio>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="crontab"
|
name="triggerCron"
|
||||||
label={t("workflow_node.start.form.trigger_cron.label")}
|
label={t("workflow_node.start.form.trigger_cron.label")}
|
||||||
hidden={triggerType !== "auto"}
|
hidden={fieldTrigger !== WORKFLOW_TRIGGERS.AUTO}
|
||||||
rules={[formRule]}
|
rules={[formRule]}
|
||||||
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.start.form.trigger_cron.tooltip") }}></span>}
|
tooltip={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.start.form.trigger_cron.tooltip") }}></span>}
|
||||||
extra={
|
extra={
|
||||||
<Show when={triggerCronLastExecutions.length > 0}>
|
<Show when={fieldTriggerCronExpectedExecutions.length > 0}>
|
||||||
<div>
|
<div>
|
||||||
{t("workflow_node.start.form.trigger_cron.extra")}
|
{t("workflow_node.start.form.trigger_cron.extra")}
|
||||||
<br />
|
<br />
|
||||||
{triggerCronLastExecutions.map((date, index) => (
|
{fieldTriggerCronExpectedExecutions.map((date, index) => (
|
||||||
<span key={index}>
|
<span key={index}>
|
||||||
{dayjs(date).format("YYYY-MM-DD HH:mm:ss")}
|
{dayjs(date).format("YYYY-MM-DD HH:mm:ss")}
|
||||||
<br />
|
<br />
|
||||||
@ -121,12 +115,14 @@ const StartNodeForm = ({ node }: StartNodeFormProps) => {
|
|||||||
</Show>
|
</Show>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Input placeholder={t("workflow_node.start.form.trigger_cron.placeholder")} onChange={(e) => handleTriggerCronChange(e.target.value)} />
|
<Input placeholder={t("workflow_node.start.form.trigger_cron.placeholder")} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item hidden={triggerType !== "auto"}>
|
<Show when={fieldTrigger === WORKFLOW_TRIGGERS.AUTO}>
|
||||||
<Alert type="info" message={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.start.form.trigger_cron_alert.content") }}></span>} />
|
<Form.Item>
|
||||||
</Form.Item>
|
<Alert type="info" message={<span dangerouslySetInnerHTML={{ __html: t("workflow_node.start.form.trigger_cron_alert.content") }}></span>} />
|
||||||
|
</Form.Item>
|
||||||
|
</Show>
|
||||||
|
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Button type="primary" htmlType="submit" loading={formPending}>
|
<Button type="primary" htmlType="submit" loading={formPending}>
|
||||||
|
@ -7,14 +7,21 @@ import i18n from "@/i18n";
|
|||||||
export interface WorkflowModel extends BaseModel {
|
export interface WorkflowModel extends BaseModel {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
type: string;
|
trigger: string;
|
||||||
crontab?: string;
|
triggerCron?: string;
|
||||||
|
enabled?: boolean;
|
||||||
content?: WorkflowNode;
|
content?: WorkflowNode;
|
||||||
draft?: WorkflowNode;
|
draft?: WorkflowNode;
|
||||||
enabled?: boolean;
|
|
||||||
hasDraft?: boolean;
|
hasDraft?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const WORKFLOW_TRIGGERS = Object.freeze({
|
||||||
|
AUTO: "auto",
|
||||||
|
MANUAL: "manual",
|
||||||
|
} as const);
|
||||||
|
|
||||||
|
export type WorkflowTriggerType = (typeof WORKFLOW_TRIGGERS)[keyof typeof WORKFLOW_TRIGGERS];
|
||||||
|
|
||||||
// #region Node
|
// #region Node
|
||||||
export enum WorkflowNodeType {
|
export enum WorkflowNodeType {
|
||||||
Start = "start",
|
Start = "start",
|
||||||
@ -86,8 +93,8 @@ export type WorkflowNode = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type WorkflowStartNodeConfig = {
|
export type WorkflowStartNodeConfig = {
|
||||||
executionMethod: string;
|
trigger: string;
|
||||||
crontab?: string;
|
triggerCron?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WorkflowApplyNodeConfig = {
|
export type WorkflowApplyNodeConfig = {
|
||||||
@ -139,7 +146,7 @@ type InitWorkflowOptions = {
|
|||||||
|
|
||||||
export const initWorkflow = (options: InitWorkflowOptions = {}): WorkflowModel => {
|
export const initWorkflow = (options: InitWorkflowOptions = {}): WorkflowModel => {
|
||||||
const root = newNode(WorkflowNodeType.Start, {}) as WorkflowNode;
|
const root = newNode(WorkflowNodeType.Start, {}) as WorkflowNode;
|
||||||
root.config = { executionMethod: "manual" };
|
root.config = { trigger: WORKFLOW_TRIGGERS.MANUAL };
|
||||||
|
|
||||||
if (options.template === "standard") {
|
if (options.template === "standard") {
|
||||||
let temp = root;
|
let temp = root;
|
||||||
@ -155,8 +162,8 @@ export const initWorkflow = (options: InitWorkflowOptions = {}): WorkflowModel =
|
|||||||
return {
|
return {
|
||||||
id: null!,
|
id: null!,
|
||||||
name: `MyWorkflow-${dayjs().format("YYYYMMDDHHmmss")}`,
|
name: `MyWorkflow-${dayjs().format("YYYYMMDDHHmmss")}`,
|
||||||
type: root.config!.executionMethod as string,
|
trigger: root.config!.trigger as string,
|
||||||
crontab: root.config!.crontab as string,
|
triggerCron: root.config!.triggerCron as string,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
draft: root,
|
draft: root,
|
||||||
hasDraft: true,
|
hasDraft: true,
|
||||||
@ -388,16 +395,19 @@ export const isAllNodesValidated = (node: WorkflowNode): boolean => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getExecuteMethod = (node: WorkflowNode): { type: string; crontab: string } => {
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export const getExecuteMethod = (node: WorkflowNode): { trigger: string; triggerCron: string } => {
|
||||||
if (node.type === WorkflowNodeType.Start) {
|
if (node.type === WorkflowNodeType.Start) {
|
||||||
return {
|
return {
|
||||||
type: (node.config?.executionMethod as string) ?? "",
|
trigger: (node.config?.trigger as string) ?? "",
|
||||||
crontab: (node.config?.crontab as string) ?? "",
|
triggerCron: (node.config?.triggerCron as string) ?? "",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
type: "",
|
trigger: "",
|
||||||
crontab: "",
|
triggerCron: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ import {
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { ClientResponseError } from "pocketbase";
|
import { ClientResponseError } from "pocketbase";
|
||||||
|
|
||||||
import { type WorkflowModel, isAllNodesValidated } from "@/domain/workflow";
|
import { WORKFLOW_TRIGGERS, type WorkflowModel, isAllNodesValidated } from "@/domain/workflow";
|
||||||
import { list as listWorkflow, remove as removeWorkflow, save as saveWorkflow } from "@/repository/workflow";
|
import { list as listWorkflow, remove as removeWorkflow, save as saveWorkflow } from "@/repository/workflow";
|
||||||
import { getErrMsg } from "@/utils/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
|
|
||||||
@ -67,16 +67,16 @@ const WorkflowList = () => {
|
|||||||
title: t("workflow.props.trigger"),
|
title: t("workflow.props.trigger"),
|
||||||
ellipsis: true,
|
ellipsis: true,
|
||||||
render: (_, record) => {
|
render: (_, record) => {
|
||||||
const trigger = record.type;
|
const trigger = record.trigger;
|
||||||
if (!trigger) {
|
if (!trigger) {
|
||||||
return "-";
|
return "-";
|
||||||
} else if (trigger === "manual") {
|
} else if (trigger === WORKFLOW_TRIGGERS.MANUAL) {
|
||||||
return <Typography.Text>{t("workflow.props.trigger.manual")}</Typography.Text>;
|
return <Typography.Text>{t("workflow.props.trigger.manual")}</Typography.Text>;
|
||||||
} else if (trigger === "auto") {
|
} else if (trigger === WORKFLOW_TRIGGERS.AUTO) {
|
||||||
return (
|
return (
|
||||||
<Space className="max-w-full" direction="vertical" size={4}>
|
<Space className="max-w-full" direction="vertical" size={4}>
|
||||||
<Typography.Text>{t("workflow.props.trigger.auto")}</Typography.Text>
|
<Typography.Text>{t("workflow.props.trigger.auto")}</Typography.Text>
|
||||||
<Typography.Text type="secondary">{record.crontab ?? ""}</Typography.Text>
|
<Typography.Text type="secondary">{record.triggerCron ?? ""}</Typography.Text>
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
|||||||
id: (get().workflow.id as string) ?? "",
|
id: (get().workflow.id as string) ?? "",
|
||||||
content: root,
|
content: root,
|
||||||
enabled: !get().workflow.enabled,
|
enabled: !get().workflow.enabled,
|
||||||
type: executeMethod.type,
|
trigger: executeMethod.trigger,
|
||||||
crontab: executeMethod.crontab,
|
triggerCron: executeMethod.triggerCron,
|
||||||
});
|
});
|
||||||
|
|
||||||
set((state: WorkflowState) => {
|
set((state: WorkflowState) => {
|
||||||
@ -79,8 +79,8 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
|||||||
id: resp.id,
|
id: resp.id,
|
||||||
content: resp.content,
|
content: resp.content,
|
||||||
enabled: resp.enabled,
|
enabled: resp.enabled,
|
||||||
type: resp.type,
|
trigger: resp.trigger,
|
||||||
crontab: resp.crontab,
|
triggerCron: resp.triggerCron,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -93,8 +93,8 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
|||||||
id: (get().workflow.id as string) ?? "",
|
id: (get().workflow.id as string) ?? "",
|
||||||
content: root,
|
content: root,
|
||||||
hasDraft: false,
|
hasDraft: false,
|
||||||
type: executeMethod.type,
|
trigger: executeMethod.trigger,
|
||||||
crontab: executeMethod.crontab,
|
triggerCron: executeMethod.triggerCron,
|
||||||
});
|
});
|
||||||
|
|
||||||
set((state: WorkflowState) => {
|
set((state: WorkflowState) => {
|
||||||
@ -104,8 +104,8 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
|||||||
id: resp.id,
|
id: resp.id,
|
||||||
content: resp.content,
|
content: resp.content,
|
||||||
hasDraft: false,
|
hasDraft: false,
|
||||||
type: resp.type,
|
trigger: resp.trigger,
|
||||||
crontab: resp.crontab,
|
triggerCron: resp.triggerCron,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user