Add liveness and readiness endpoints to appservices

This commit is contained in:
Tulir Asokan 2021-08-25 18:38:30 +03:00
commit 386ac2e0c6
2 changed files with 27 additions and 0 deletions

View file

@ -46,6 +46,8 @@ func Create() *AppService {
StateStore: NewBasicStateStore(),
Router: mux.NewRouter(),
UserAgent: mautrix.DefaultUserAgent,
Live: true,
Ready: false,
}
}
@ -105,6 +107,9 @@ type AppService struct {
DefaultHTTPRetries int
Live bool
Ready bool
clients map[id.UserID]*mautrix.Client
clientsLock sync.RWMutex
intents map[id.UserID]*IntentAPI

View file

@ -30,6 +30,8 @@ func (as *AppService) Start() {
as.Router.HandleFunc("/_matrix/app/v1/transactions/{txnID}", as.PutTransaction).Methods(http.MethodPut)
as.Router.HandleFunc("/_matrix/app/v1/rooms/{roomAlias}", as.GetRoom).Methods(http.MethodGet)
as.Router.HandleFunc("/_matrix/app/v1/users/{userID}", as.GetUser).Methods(http.MethodGet)
as.Router.HandleFunc("/_matrix/mau/live", as.GetLive).Methods(http.MethodGet)
as.Router.HandleFunc("/_matrix/mau/ready", as.GetReady).Methods(http.MethodGet)
var err error
as.server = &http.Server{
@ -237,3 +239,23 @@ func (as *AppService) GetUser(w http.ResponseWriter, r *http.Request) {
}.Write(w)
}
}
func (as *AppService) GetLive(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
if as.Live {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusInternalServerError)
}
w.Write([]byte("{}"))
}
func (as *AppService) GetReady(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
if as.Ready {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusInternalServerError)
}
w.Write([]byte("{}"))
}