msg.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package internal
  2. import "time"
  3. // A StatusUpdateMsg represents a msg when
  4. // a worker has done syncing
  5. type MirrorStatus struct {
  6. Name string `json:"name"`
  7. Worker string `json:"worker"`
  8. IsMaster bool `json:"is_master"`
  9. Status SyncStatus `json:"status"`
  10. LastUpdate time.Time `json:"last_update"`
  11. Upstream string `json:"upstream"`
  12. Size string `json:"size"`
  13. ErrorMsg string `json:"error_msg"`
  14. }
  15. // A WorkerStatus is the information struct that describe
  16. // a worker, and sent from the manager to clients.
  17. type WorkerStatus struct {
  18. ID string `json:"id"`
  19. URL string `json:"url"` // worker url
  20. Token string `json:"token"` // session token
  21. LastOnline time.Time `json:"last_online"` // last seen
  22. }
  23. type CmdVerb uint8
  24. const (
  25. CmdStart CmdVerb = iota
  26. CmdStop // stop syncing keep the job
  27. CmdDisable // disable the job (stops goroutine)
  28. CmdRestart // restart syncing
  29. CmdPing // ensure the goroutine is alive
  30. )
  31. // A WorkerCmd is the command message send from the
  32. // manager to a worker
  33. type WorkerCmd struct {
  34. Cmd CmdVerb `json:"cmd"`
  35. MirrorID string `json:"mirror_id"`
  36. Args []string `json:"args"`
  37. }
  38. // A ClientCmd is the command message send from client
  39. // to the manager
  40. type ClientCmd struct {
  41. Cmd CmdVerb `json:"cmd"`
  42. MirrorID string `json:"mirror_id"`
  43. WorkerID string `json:"worker_id"`
  44. Args []string `json:"args"`
  45. }