| 1 | package console |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | func (s *Server) registerClaimWorkers() { |
| 6 | s.claimWorkers = map[string]func(context.Context){} |
| 7 | for name, h := range map[string]func(context.Context){ |
| 8 | "StartHostReports": s.StartHostReports, |
| 9 | "StartAlertWatcher": s.StartAlertWatcher, |
| 10 | "StartGeoipJobs": s.StartGeoipJobs, |
| 11 | "StartClaimRecoveryPass": s.StartClaimRecoveryPass, |
| 12 | "StartEconomicsPass": s.StartEconomicsPass, |
| 13 | "StartInfraPass": s.StartInfraPass, |
| 14 | "StartScanPass": s.StartScanPass, |
| 15 | "StartScanDrain": s.StartScanDrain, |
| 16 | "StartExpiryPass": s.StartExpiryPass, |
| 17 | "StartPlanLimitsPass": s.StartPlanLimitsPass, |
| 18 | "PublishPlansMarker": s.PublishPlansMarker, |
| 19 | "StartRunSweep": s.StartRunSweep, |
| 20 | "StartSeedsPass": s.StartSeedsPass, |
| 21 | "StartRelay": s.StartRelay, |
| 22 | "StartMailEventPush": s.StartMailEventPush, |
| 23 | "StartDoorKeyResign": s.StartDoorKeyResign, |
| 24 | "ReportApexSquats": s.ReportApexSquats, |
| 25 | "LogPlacementDiscrepancies": s.LogPlacementDiscrepancies, |
| 26 | "PublishMovesConsole": s.publishMovesConsoleWorker, |
| 27 | } { |
| 28 | e := claimEntry{Kind: "worker", Pattern: name, Handler: claimHandlerName(h)} |
| 29 | s.claimEntries.add(e) |
| 30 | if !s.cfg.HostClaim { |
| 31 | s.claimWorkers[name] = h |
| 32 | continue |
| 33 | } |
| 34 | s.claimWorkers[name] = func(ctx context.Context) { h(context.WithValue(ctx, claimEntryKey{}, e)) } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // publishMovesConsoleWorker is PublishMovesConsole as a recorded worker. The |
| 39 | // method logs its own failure (it is best-effort and the console serves |
| 40 | // regardless), so the worker drops the returned error. It is a no-op with the |
| 41 | // moves switch off. |
| 42 | func (s *Server) publishMovesConsoleWorker(ctx context.Context) { _ = s.PublishMovesConsole(ctx) } |
| 43 | |
| 44 | func (s *Server) RunClaimWorker(ctx context.Context, name string) { |
| 45 | h, ok := s.claimWorkers[name] |
| 46 | if !ok { |
| 47 | panic("unregistered console worker: " + name) |
| 48 | } |
| 49 | h(ctx) |
| 50 | } |
| 51 | |