handleTriggerSync manually triggers a sync for an account.
(w http.ResponseWriter, r *http.Request)
| 885 | |
| 886 | // handleTriggerSync manually triggers a sync for an account. |
| 887 | func (s *Server) handleTriggerSync(w http.ResponseWriter, r *http.Request) { |
| 888 | if s.scheduler == nil { |
| 889 | writeError(w, http.StatusServiceUnavailable, "scheduler_unavailable", "Scheduler not available") |
| 890 | return |
| 891 | } |
| 892 | |
| 893 | account := chi.URLParam(r, "account") |
| 894 | if account == "" { |
| 895 | writeError(w, http.StatusBadRequest, "missing_account", "Account email is required") |
| 896 | return |
| 897 | } |
| 898 | |
| 899 | if !s.scheduler.IsScheduled(account) { |
| 900 | writeError(w, http.StatusNotFound, "not_found", "Account is not scheduled: "+account) |
| 901 | return |
| 902 | } |
| 903 | |
| 904 | err := s.scheduler.TriggerSync(account) |
| 905 | if err != nil { |
| 906 | s.logger.Error("failed to trigger sync", "account", account, "error", err) |
| 907 | writeError(w, http.StatusConflict, "sync_error", err.Error()) |
| 908 | return |
| 909 | } |
| 910 | |
| 911 | s.logger.Info("sync triggered via API", "account", account) |
| 912 | writeJSON(w, http.StatusAccepted, map[string]string{ |
| 913 | "status": "accepted", |
| 914 | "message": "Sync started for " + account, |
| 915 | }) |
| 916 | } |
| 917 | |
| 918 | // handleSchedulerStatus returns the scheduler status. |
| 919 | func (s *Server) handleSchedulerStatus(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected