MCPcopy
hub / github.com/kenn-io/msgvault / handleTriggerSync

Method handleTriggerSync

internal/api/handlers.go:887–916  ·  view source on GitHub ↗

handleTriggerSync manually triggers a sync for an account.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

885
886// handleTriggerSync manually triggers a sync for an account.
887func (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.
919func (s *Server) handleSchedulerStatus(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 5

writeErrorFunction · 0.85
writeJSONFunction · 0.70
IsScheduledMethod · 0.65
TriggerSyncMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected