2
0

msg.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package internal
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. // A MirrorStatus represents a msg when
  7. // a worker has done syncing
  8. type MirrorStatus struct {
  9. Name string `json:"name"`
  10. Worker string `json:"worker"`
  11. IsMaster bool `json:"is_master"`
  12. Status SyncStatus `json:"status"`
  13. LastUpdate time.Time `json:"last_update"`
  14. Upstream string `json:"upstream"`
  15. Size string `json:"size"`
  16. ErrorMsg string `json:"error_msg"`
  17. }
  18. // A WorkerStatus is the information struct that describe
  19. // a worker, and sent from the manager to clients.
  20. type WorkerStatus struct {
  21. ID string `json:"id"`
  22. URL string `json:"url"` // worker url
  23. Token string `json:"token"` // session token
  24. LastOnline time.Time `json:"last_online"` // last seen
  25. }
  26. // A CmdVerb is an action to a job or worker
  27. type CmdVerb uint8
  28. const (
  29. // CmdStart start a job
  30. CmdStart CmdVerb = iota
  31. // CmdStop stop syncing, but keep the job
  32. CmdStop
  33. // CmdDisable disable the job (stops goroutine)
  34. CmdDisable
  35. // CmdRestart restart a syncing job
  36. CmdRestart
  37. // CmdPing ensures the goroutine is alive
  38. CmdPing
  39. // CmdReload tells a worker to reload mirror config
  40. CmdReload
  41. )
  42. func (c CmdVerb) String() string {
  43. switch c {
  44. case CmdStart:
  45. return "start"
  46. case CmdStop:
  47. return "stop"
  48. case CmdDisable:
  49. return "disable"
  50. case CmdRestart:
  51. return "restart"
  52. case CmdPing:
  53. return "ping"
  54. case CmdReload:
  55. return "reload"
  56. }
  57. return "unknown"
  58. }
  59. // A WorkerCmd is the command message send from the
  60. // manager to a worker
  61. type WorkerCmd struct {
  62. Cmd CmdVerb `json:"cmd"`
  63. MirrorID string `json:"mirror_id"`
  64. Args []string `json:"args"`
  65. }
  66. func (c WorkerCmd) String() string {
  67. if len(c.Args) > 0 {
  68. return fmt.Sprintf("%v (%s, %v)", c.Cmd, c.MirrorID, c.Args)
  69. }
  70. return fmt.Sprintf("%v (%s)", c.Cmd, c.MirrorID)
  71. }
  72. // A ClientCmd is the command message send from client
  73. // to the manager
  74. type ClientCmd struct {
  75. Cmd CmdVerb `json:"cmd"`
  76. MirrorID string `json:"mirror_id"`
  77. WorkerID string `json:"worker_id"`
  78. Args []string `json:"args"`
  79. }