2
0

msg.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. LastStarted time.Time `json:"last_started"`
  15. LastEnded time.Time `json:"last_ended"`
  16. Scheduled time.Time `json:"next_schedule"`
  17. Upstream string `json:"upstream"`
  18. Size string `json:"size"`
  19. ErrorMsg string `json:"error_msg"`
  20. }
  21. // A WorkerStatus is the information struct that describe
  22. // a worker, and sent from the manager to clients.
  23. type WorkerStatus struct {
  24. ID string `json:"id"`
  25. URL string `json:"url"` // worker url
  26. Token string `json:"token"` // session token
  27. LastOnline time.Time `json:"last_online"` // last seen
  28. LastRegister time.Time `json:"last_register"` // last register time
  29. }
  30. type MirrorSchedules struct {
  31. Schedules []MirrorSchedule `json:"schedules"`
  32. }
  33. type MirrorSchedule struct {
  34. MirrorName string `json:"name"`
  35. NextSchedule time.Time `json:"next_schedule"`
  36. }
  37. // A CmdVerb is an action to a job or worker
  38. type CmdVerb uint8
  39. const (
  40. // CmdStart start a job
  41. CmdStart CmdVerb = iota
  42. // CmdStop stop syncing, but keep the job
  43. CmdStop
  44. // CmdDisable disable the job (stops goroutine)
  45. CmdDisable
  46. // CmdRestart restart a syncing job
  47. CmdRestart
  48. // CmdPing ensures the goroutine is alive
  49. CmdPing
  50. // CmdReload tells a worker to reload mirror config
  51. CmdReload
  52. )
  53. func (c CmdVerb) String() string {
  54. switch c {
  55. case CmdStart:
  56. return "start"
  57. case CmdStop:
  58. return "stop"
  59. case CmdDisable:
  60. return "disable"
  61. case CmdRestart:
  62. return "restart"
  63. case CmdPing:
  64. return "ping"
  65. case CmdReload:
  66. return "reload"
  67. }
  68. return "unknown"
  69. }
  70. // A WorkerCmd is the command message send from the
  71. // manager to a worker
  72. type WorkerCmd struct {
  73. Cmd CmdVerb `json:"cmd"`
  74. MirrorID string `json:"mirror_id"`
  75. Args []string `json:"args"`
  76. Options map[string]bool `json:"options"`
  77. }
  78. func (c WorkerCmd) String() string {
  79. if len(c.Args) > 0 {
  80. return fmt.Sprintf("%v (%s, %v)", c.Cmd, c.MirrorID, c.Args)
  81. }
  82. return fmt.Sprintf("%v (%s)", c.Cmd, c.MirrorID)
  83. }
  84. // A ClientCmd is the command message send from client
  85. // to the manager
  86. type ClientCmd struct {
  87. Cmd CmdVerb `json:"cmd"`
  88. MirrorID string `json:"mirror_id"`
  89. WorkerID string `json:"worker_id"`
  90. Args []string `json:"args"`
  91. Options map[string]bool `json:"options"`
  92. }