-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
79 lines (69 loc) · 2.24 KB
/
types.go
File metadata and controls
79 lines (69 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Package goserver defines the core types and structures for the distributed task scheduling system.
package goserver
import (
"encoding/json"
"sync"
"time"
"github.com/gorilla/websocket"
)
// TaskStatus 任务状态
type TaskStatus string
type Task struct {
ID string
Method string
Params json.RawMessage
Result any
Worker *Worker
Created time.Time
Completed time.Time // 任务完成时间
Status TaskStatus // "pending", "processing", "done", "error"
}
type Worker struct {
Conn *websocket.Conn
Methods []MethodInfo
ConnMu sync.Mutex // 保护websocket连接的并发写入
LastPing int64 // 使用原子操作,存储Unix纳秒时间戳
Count int64 // 使用原子操作
ID string
IP string // Worker的IP地址
Group string // Worker的分组
}
type WorkerInfo struct {
Methods []MethodInfo `json:"methods"`
LastPing time.Time `json:"lastPing"`
Count int64 `json:"count"`
ID string `json:"id"`
IP string `json:"ip"`
Group string `json:"group"`
}
type MethodInfo struct {
Name string `json:"name"`
Docs []string `json:"docs"`
}
// EncryptedRequest 端到端加密请求结构
type EncryptedRequest struct {
Key string `json:"key"` // 用户加盐后的密钥
Method string `json:"method"` // 需要调用的方法名
Params string `json:"params"` // 用户加密后的调用参数
Crypto string `json:"crypto"` // 用户加盐的实际数据(如位运算)
}
// EncryptedTask 端到端加密任务结构(调度器只做中转)
type EncryptedTask struct {
Result interface{} `json:"result"`
Worker *Worker `json:"-"`
Created time.Time `json:"created"`
Completed time.Time `json:"completed"` // 任务完成时间
ID string `json:"id"`
Key string `json:"key"`
Method string `json:"method"`
Params string `json:"params"`
Crypto string `json:"crypto"`
Status TaskStatus `json:"status"`
}
// TaskResultMessage represents the message structure for task results
type TaskResultMessage struct {
Type string `json:"type"`
TaskID string `json:"taskId"`
Error string `json:"error"`
Result json.RawMessage `json:"result"`
}