wip: flow task start
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package model
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type ESDoc struct {
|
||||
DocId string `json:"_id"`
|
||||
Index string `json:"_index"`
|
||||
@@ -10,6 +12,10 @@ func (d *ESDoc) ToMap() map[string]any {
|
||||
return map[string]any{"_id": d.DocId, "_index": d.Index, "_source": d.Content}
|
||||
}
|
||||
|
||||
func (d *ESDoc) Bytes() ([]byte, error) {
|
||||
return json.Marshal(d)
|
||||
}
|
||||
|
||||
type ESResponse struct {
|
||||
ScrollId string `json:"_scroll_id"`
|
||||
Took int `json:"took"`
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package model
|
||||
|
||||
type Enum interface {
|
||||
Value() int64
|
||||
Code() string
|
||||
Label() string
|
||||
|
||||
MarshalJSON() ([]byte, error)
|
||||
|
||||
All() []Enum
|
||||
}
|
||||
|
||||
type OpLogger interface {
|
||||
Enum
|
||||
Render(content map[string]any) (string, error)
|
||||
Template() string
|
||||
}
|
||||
|
||||
type TaskRow interface {
|
||||
Preview() map[string]any
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"github.com/loveuer/nfflow/internal/interfaces"
|
||||
"github.com/loveuer/nfflow/internal/sqlType"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/tdewolff/minify/v2"
|
||||
@@ -21,7 +22,7 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
_ OpLogger = OpLogType(0)
|
||||
_ interfaces.OpLogger = OpLogType(0)
|
||||
)
|
||||
|
||||
type OpLogType uint64
|
||||
@@ -82,8 +83,8 @@ func (o OpLogType) MarshalJSON() ([]byte, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (o OpLogType) All() []Enum {
|
||||
return []Enum{
|
||||
func (o OpLogType) All() []interfaces.Enum {
|
||||
return []interfaces.Enum{
|
||||
OpLogTypeLogin,
|
||||
OpLogTypeLogout,
|
||||
OpLogTypeCreateUser,
|
||||
|
||||
@@ -2,10 +2,8 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/loveuer/nfflow/internal/interfaces"
|
||||
"github.com/loveuer/nfflow/internal/sqlType"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type InputType int64
|
||||
@@ -50,15 +48,15 @@ func (p PipeType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(map[string]any{"value": p.Value(), "code": p.Code(), "label": p.Label()})
|
||||
}
|
||||
|
||||
func (p PipeType) All() []Enum {
|
||||
return []Enum{PipeTypeLoadashMap}
|
||||
func (p PipeType) All() []interfaces.Enum {
|
||||
return []interfaces.Enum{PipeTypeLoadashMap}
|
||||
}
|
||||
|
||||
const (
|
||||
PipeTypeLoadashMap PipeType = iota + 1
|
||||
)
|
||||
|
||||
var _ Enum = PipeType(0)
|
||||
var _ interfaces.Enum = (*PipeType)(nil)
|
||||
|
||||
type TaskStatus int64
|
||||
|
||||
@@ -70,8 +68,8 @@ func (t TaskStatus) MarshalJSON() ([]byte, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (t TaskStatus) All() []Enum {
|
||||
return []Enum{
|
||||
func (t TaskStatus) All() []interfaces.Enum {
|
||||
return []interfaces.Enum{
|
||||
TaskStatusNotReady,
|
||||
TaskStatusReady,
|
||||
TaskStatusRunning,
|
||||
@@ -80,7 +78,7 @@ func (t TaskStatus) All() []Enum {
|
||||
}
|
||||
}
|
||||
|
||||
var _ Enum = TaskStatus(0)
|
||||
var _ interfaces.Enum = (*TaskStatus)(nil)
|
||||
|
||||
const (
|
||||
TaskStatusNotReady TaskStatus = iota
|
||||
@@ -168,11 +166,11 @@ func (t TaskRunType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(map[string]any{"code": t.Code(), "value": t.Value(), "label": t.Label()})
|
||||
}
|
||||
|
||||
func (t TaskRunType) All() []Enum {
|
||||
return []Enum{TaskRunTypeOnce, TaskRunTypeTiming, TaskRunTypeCron}
|
||||
func (t TaskRunType) All() []interfaces.Enum {
|
||||
return []interfaces.Enum{TaskRunTypeOnce, TaskRunTypeTiming, TaskRunTypeCron}
|
||||
}
|
||||
|
||||
var _ Enum = TaskRunType(0)
|
||||
var _ interfaces.Enum = TaskRunType(0)
|
||||
|
||||
type Task struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
@@ -190,89 +188,26 @@ type Task struct {
|
||||
}
|
||||
|
||||
type TaskInput struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
TaskId uint64 `json:"task_id" gorm:"column:task_id"`
|
||||
Type InputType `json:"type" gorm:"column:type"`
|
||||
Config sqlType.JSONB `json:"config" gorm:"config"`
|
||||
}
|
||||
|
||||
func (t *Task) GetInput(tx *gorm.DB) (*TaskInput, error) {
|
||||
var (
|
||||
err error
|
||||
ti = new(TaskInput)
|
||||
)
|
||||
|
||||
if err = tx.Model(&TaskInput{}).
|
||||
Where("task_id", t.Id).
|
||||
Take(ti).
|
||||
Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ti, nil
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
TaskId uint64 `json:"task_id" gorm:"column:task_id"`
|
||||
Type InputType `json:"type" gorm:"column:type"`
|
||||
Config sqlType.JSONB `json:"config" gorm:"config"`
|
||||
Instance interfaces.Input `json:"instance" gorm:"-"`
|
||||
}
|
||||
|
||||
type TaskOutput struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
TaskId uint64 `json:"task_id" gorm:"column:task_id"`
|
||||
Type OutputType `json:"type" gorm:"column:type"`
|
||||
Config sqlType.JSONB `json:"config" gorm:"config"`
|
||||
}
|
||||
|
||||
func (t *Task) GetOutputs(tx *gorm.DB) ([]*TaskOutput, error) {
|
||||
var (
|
||||
err error
|
||||
outputs = make([]*TaskOutput, 0)
|
||||
)
|
||||
|
||||
if err = tx.Model(&TaskOutput{}).
|
||||
Where("task_id", t.Id).
|
||||
Find(&outputs).
|
||||
Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return outputs, nil
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
TaskId uint64 `json:"task_id" gorm:"column:task_id"`
|
||||
Type OutputType `json:"type" gorm:"column:type"`
|
||||
Config sqlType.JSONB `json:"config" gorm:"config"`
|
||||
Instance interfaces.Output `json:"instance" gorm:"-"`
|
||||
}
|
||||
|
||||
type TaskPipe struct {
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
TaskId uint64 `json:"task_id" gorm:"column:task_id"`
|
||||
Pid uint64 `json:"pid" gorm:"column:pid"`
|
||||
Type PipeType `json:"type" gorm:"column:type"`
|
||||
Config sqlType.JSONB `json:"config" gorm:"config"`
|
||||
Next []*TaskPipe `json:"next" gorm:"-"`
|
||||
}
|
||||
|
||||
func (t *Task) GetPipes(tx *gorm.DB) ([]*TaskPipe, error) {
|
||||
var (
|
||||
err error
|
||||
list = make([]*TaskPipe, 0)
|
||||
)
|
||||
|
||||
if err = tx.Model(&TaskPipe{}).
|
||||
Where("task_id", t.Id).
|
||||
Find(&list).
|
||||
Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := lo.SliceToMap(list, func(item *TaskPipe) (uint64, *TaskPipe) {
|
||||
item.Next = make([]*TaskPipe, 0)
|
||||
return item.Id, item
|
||||
})
|
||||
|
||||
m[0] = &TaskPipe{Next: make([]*TaskPipe, 0)}
|
||||
|
||||
for idx := range list {
|
||||
x := list[idx]
|
||||
if _, exist := m[x.Pid]; !exist {
|
||||
logrus.Warnf("GetPipes: pipe=[task_id=%d id=%d pid=%d type=%s] pid not found", x.TaskId, x.Id, x.Pid, x.Type.Code())
|
||||
continue
|
||||
}
|
||||
|
||||
m[x.Pid].Next = append(m[x.Pid].Next, x)
|
||||
}
|
||||
|
||||
return m[0].Next, nil
|
||||
Id uint64 `json:"id" gorm:"primaryKey;column:id"`
|
||||
TaskId uint64 `json:"task_id" gorm:"column:task_id"`
|
||||
Sort int `json:"sort" gorm:"column:sort"`
|
||||
Type PipeType `json:"type" gorm:"column:type"`
|
||||
Config sqlType.JSONB `json:"config" gorm:"config"`
|
||||
Instance interfaces.Pipe `json:"instance" gorm:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user