mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:22:46 +00:00
feature(manager): skeleton for worker-manager communication
This commit is contained in:
parent
681388ffdd
commit
afee5b2a81
42
internal/msg.go
Normal file
42
internal/msg.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// A StatusUpdateMsg represents a msg when
|
||||||
|
// a worker has done syncing
|
||||||
|
type StatusUpdateMsg struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Worker string `json:"worker"`
|
||||||
|
IsMaster bool `json:"is_master"`
|
||||||
|
Status SyncStatus `json:"status"`
|
||||||
|
LastUpdate time.Time `json:"last_update"`
|
||||||
|
Upstream string `json:"upstream"`
|
||||||
|
Size string `json:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// A WorkerInfoMsg is
|
||||||
|
type WorkerInfoMsg struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CmdVerb uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
CmdStart CmdVerb = iota
|
||||||
|
CmdStop // stop syncing keep the job
|
||||||
|
CmdDisable // disable the job (stops goroutine)
|
||||||
|
CmdRestart // restart syncing
|
||||||
|
CmdPing // ensure the goroutine is alive
|
||||||
|
)
|
||||||
|
|
||||||
|
type WorkerCmd struct {
|
||||||
|
Cmd CmdVerb `json:"cmd"`
|
||||||
|
Args []string `json:"args"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientCmd struct {
|
||||||
|
Cmd CmdVerb `json:"cmd"`
|
||||||
|
MirrorID string `json:"mirror_id"`
|
||||||
|
WorkerID string `json:"worker_id"`
|
||||||
|
Args []string `json:"args"`
|
||||||
|
}
|
23
manager/db.go
Normal file
23
manager/db.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package manager
|
||||||
|
|
||||||
|
import "github.com/boltdb/bolt"
|
||||||
|
|
||||||
|
type dbAdapter interface {
|
||||||
|
GetWorker(workerID string)
|
||||||
|
UpdateMirrorStatus(workerID, mirrorID string, status mirrorStatus)
|
||||||
|
GetMirrorStatus(workerID, mirrorID string)
|
||||||
|
GetMirrorStatusList(workerID string)
|
||||||
|
Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
type boltAdapter struct {
|
||||||
|
db *bolt.DB
|
||||||
|
dbFile string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *boltAdapter) Close() error {
|
||||||
|
if b.db != nil {
|
||||||
|
return b.db.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -23,14 +23,20 @@ func makeHTTPServer(debug bool) *gin.Engine {
|
|||||||
r.GET("/ping", func(c *gin.Context) {
|
r.GET("/ping", func(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, gin.H{"msg": "pong"})
|
c.JSON(http.StatusOK, gin.H{"msg": "pong"})
|
||||||
})
|
})
|
||||||
// List jobs, status page
|
// list jobs, status page
|
||||||
r.GET("/jobs", func(c *gin.Context) {})
|
r.GET("/jobs", func(c *gin.Context) {})
|
||||||
// worker online
|
// worker online
|
||||||
r.POST("/workers/:name", func(c *gin.Context) {})
|
r.POST("/workers/:name", func(c *gin.Context) {})
|
||||||
// post job list
|
// get job list
|
||||||
r.POST("/workers/:name/jobs", func(c *gin.Context) {})
|
r.GET("/workers/:name/jobs", func(c *gin.Context) {})
|
||||||
// post job status
|
// post job status
|
||||||
r.POST("/workers/:name/jobs/:job", func(c *gin.Context) {})
|
r.POST("/workers/:name/jobs/:job", func(c *gin.Context) {})
|
||||||
|
|
||||||
|
// worker command polling
|
||||||
|
r.GET("/workers/:name/cmd_stream", func(c *gin.Context) {})
|
||||||
|
|
||||||
|
// for tunasynctl to post commands
|
||||||
|
r.POST("/cmd/", func(c *gin.Context) {})
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user