mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-07 21:19:51 +00:00
feat: rename workflow_run_log
to workflow_run
This commit is contained in:
parent
01ede08a79
commit
b686579acc
@ -4,9 +4,9 @@ const WorkflowOutputCertificate = "certificate"
|
||||
|
||||
type WorkflowOutput struct {
|
||||
Meta
|
||||
WorkflowId string `json:"workflowId" db:"workflowId"`
|
||||
WorkflowId string `json:"workflowId" db:"workflow"`
|
||||
NodeId string `json:"nodeId" db:"nodeId"`
|
||||
Node *WorkflowNode `json:"node" db:"node"`
|
||||
Outputs []WorkflowNodeIO `json:"outputs" db:"outputs"`
|
||||
Succeeded bool `json:"succeeded"db:"succeeded"`
|
||||
Succeeded bool `json:"succeeded" db:"succeeded"`
|
||||
}
|
||||
|
40
internal/domain/workflow_run.go
Normal file
40
internal/domain/workflow_run.go
Normal file
@ -0,0 +1,40 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type WorkflowRun struct {
|
||||
Meta
|
||||
WorkflowId string `json:"workflowId" db:"workflowId"`
|
||||
Trigger string `json:"trigger" db:"trigger"`
|
||||
StartedAt time.Time `json:"startedAt" db:"startedAt"`
|
||||
CompletedAt time.Time `json:"completedAt" db:"completedAt"`
|
||||
Logs []WorkflowRunLog `json:"logs" db:"logs"`
|
||||
Succeeded bool `json:"succeeded" db:"succeeded"`
|
||||
Error string `json:"error" db:"error"`
|
||||
}
|
||||
|
||||
type WorkflowRunLog struct {
|
||||
NodeId string `json:"nodeId"`
|
||||
NodeName string `json:"nodeName"`
|
||||
Error string `json:"error"`
|
||||
Outputs []WorkflowRunLogOutput `json:"outputs"`
|
||||
}
|
||||
|
||||
type WorkflowRunLogOutput struct {
|
||||
Time string `json:"time"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
type WorkflowRunLogs []WorkflowRunLog
|
||||
|
||||
func (r WorkflowRunLogs) FirstError() string {
|
||||
for _, log := range r {
|
||||
if log.Error != "" {
|
||||
return log.Error
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package domain
|
||||
|
||||
type WorkflowRunLog struct {
|
||||
Meta
|
||||
WorkflowId string `json:"workflowId" db:"workflowId"`
|
||||
Logs []RunLog `json:"logs" db:"logs"`
|
||||
Succeeded bool `json:"succeeded" db:"succeeded"`
|
||||
Error string `json:"error" db:"error"`
|
||||
}
|
||||
|
||||
type RunLogOutput struct {
|
||||
Time string `json:"time"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
type RunLog struct {
|
||||
NodeId string `json:"nodeId"`
|
||||
NodeName string `json:"nodeName"`
|
||||
Error string `json:"error"`
|
||||
Outputs []RunLogOutput `json:"outputs"`
|
||||
}
|
||||
|
||||
type RunLogs []RunLog
|
||||
|
||||
func (r RunLogs) Error() string {
|
||||
for _, log := range r {
|
||||
if log.Error != "" {
|
||||
return log.Error
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
@ -37,14 +37,17 @@ func (w *WorkflowRepository) ListEnabledAuto(ctx context.Context) ([]domain.Work
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
func (w *WorkflowRepository) SaveRunLog(ctx context.Context, log *domain.WorkflowRunLog) error {
|
||||
collection, err := app.GetApp().Dao().FindCollectionByNameOrId("workflow_run_log")
|
||||
func (w *WorkflowRepository) SaveRunLog(ctx context.Context, log *domain.WorkflowRun) error {
|
||||
collection, err := app.GetApp().Dao().FindCollectionByNameOrId("workflow_run")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
record := models.NewRecord(collection)
|
||||
|
||||
record.Set("workflowId", log.WorkflowId)
|
||||
record.Set("trigger", log.Trigger)
|
||||
record.Set("startedAt", log.StartedAt)
|
||||
record.Set("completedAt", log.CompletedAt)
|
||||
record.Set("logs", log.Logs)
|
||||
record.Set("succeeded", log.Succeeded)
|
||||
record.Set("error", log.Error)
|
||||
|
@ -10,30 +10,30 @@ import (
|
||||
|
||||
type NodeProcessor interface {
|
||||
Run(ctx context.Context) error
|
||||
Log(ctx context.Context) *domain.RunLog
|
||||
Log(ctx context.Context) *domain.WorkflowRunLog
|
||||
AddOutput(ctx context.Context, title, content string, err ...string)
|
||||
}
|
||||
|
||||
type Logger struct {
|
||||
log *domain.RunLog
|
||||
log *domain.WorkflowRunLog
|
||||
}
|
||||
|
||||
func NewLogger(node *domain.WorkflowNode) *Logger {
|
||||
return &Logger{
|
||||
log: &domain.RunLog{
|
||||
log: &domain.WorkflowRunLog{
|
||||
NodeId: node.Id,
|
||||
NodeName: node.Name,
|
||||
Outputs: make([]domain.RunLogOutput, 0),
|
||||
Outputs: make([]domain.WorkflowRunLogOutput, 0),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Logger) Log(ctx context.Context) *domain.RunLog {
|
||||
func (l *Logger) Log(ctx context.Context) *domain.WorkflowRunLog {
|
||||
return l.log
|
||||
}
|
||||
|
||||
func (l *Logger) AddOutput(ctx context.Context, title, content string, err ...string) {
|
||||
output := domain.RunLogOutput{
|
||||
output := domain.WorkflowRunLogOutput{
|
||||
Time: time.Now().UTC().Format(time.RFC3339),
|
||||
Title: title,
|
||||
Content: content,
|
||||
|
@ -8,17 +8,17 @@ import (
|
||||
|
||||
type workflowProcessor struct {
|
||||
workflow *domain.Workflow
|
||||
logs []domain.RunLog
|
||||
logs []domain.WorkflowRunLog
|
||||
}
|
||||
|
||||
func NewWorkflowProcessor(workflow *domain.Workflow) *workflowProcessor {
|
||||
return &workflowProcessor{
|
||||
workflow: workflow,
|
||||
logs: make([]domain.RunLog, 0),
|
||||
logs: make([]domain.WorkflowRunLog, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (w *workflowProcessor) Log(ctx context.Context) []domain.RunLog {
|
||||
func (w *workflowProcessor) Log(ctx context.Context) []domain.WorkflowRunLog {
|
||||
return w.logs
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type WorkflowRepository interface {
|
||||
Get(ctx context.Context, id string) (*domain.Workflow, error)
|
||||
SaveRunLog(ctx context.Context, log *domain.WorkflowRunLog) error
|
||||
SaveRunLog(ctx context.Context, log *domain.WorkflowRun) error
|
||||
ListEnabledAuto(ctx context.Context) ([]domain.Workflow, error)
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (s *WorkflowService) Run(ctx context.Context, req *domain.WorkflowRunReq) e
|
||||
|
||||
processor := nodeprocessor.NewWorkflowProcessor(workflow)
|
||||
if err := processor.Run(ctx); err != nil {
|
||||
log := &domain.WorkflowRunLog{
|
||||
log := &domain.WorkflowRun{
|
||||
WorkflowId: workflow.Id,
|
||||
Logs: processor.Log(ctx),
|
||||
Succeeded: false,
|
||||
@ -82,13 +82,13 @@ func (s *WorkflowService) Run(ctx context.Context, req *domain.WorkflowRunReq) e
|
||||
|
||||
// 保存执行日志
|
||||
logs := processor.Log(ctx)
|
||||
runLogs := domain.RunLogs(logs)
|
||||
runErr := runLogs.Error()
|
||||
runLogs := domain.WorkflowRunLogs(logs)
|
||||
runErr := runLogs.FirstError()
|
||||
succeed := true
|
||||
if runErr != "" {
|
||||
succeed = false
|
||||
}
|
||||
log := &domain.WorkflowRunLog{
|
||||
log := &domain.WorkflowRun{
|
||||
WorkflowId: workflow.Id,
|
||||
Logs: processor.Log(ctx),
|
||||
Error: runErr,
|
||||
|
105
migrations/1735980691_updated_workflow_run_log.go
Normal file
105
migrations/1735980691_updated_workflow_run_log.go
Normal file
@ -0,0 +1,105 @@
|
||||
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("qjp8lygssgwyqyz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
collection.Name = "workflow_run"
|
||||
|
||||
// add
|
||||
new_trigger := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "jlroa3fk",
|
||||
"name": "trigger",
|
||||
"type": "select",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSelect": 1,
|
||||
"values": [
|
||||
"auto",
|
||||
"manual"
|
||||
]
|
||||
}
|
||||
}`), new_trigger); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_trigger)
|
||||
|
||||
// add
|
||||
new_startedAt := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "k9xvtf89",
|
||||
"name": "startedAt",
|
||||
"type": "date",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": "",
|
||||
"max": ""
|
||||
}
|
||||
}`), new_startedAt); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_startedAt)
|
||||
|
||||
// add
|
||||
new_endedAt := &schema.SchemaField{}
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "3ikum7mk",
|
||||
"name": "endedAt",
|
||||
"type": "date",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": "",
|
||||
"max": ""
|
||||
}
|
||||
}`), new_endedAt); err != nil {
|
||||
return err
|
||||
}
|
||||
collection.Schema.AddField(new_endedAt)
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("qjp8lygssgwyqyz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
collection.Name = "workflow_run_log"
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("jlroa3fk")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("k9xvtf89")
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("3ikum7mk")
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
})
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
import { getPocketBase } from "./pocketbase";
|
||||
|
||||
const COLLECTION_NAME = "workflow_run_log";
|
||||
const COLLECTION_NAME = "workflow_run";
|
||||
|
||||
export type ListWorkflowRunsRequest = {
|
||||
workflowId: string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user