Skip to content

Commit

Permalink
Add liveness and readiness endpoints to appservices
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 25, 2021
1 parent 53be7e7 commit 386ac2e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions appservice/appservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func Create() *AppService {
StateStore: NewBasicStateStore(),
Router: mux.NewRouter(),
UserAgent: mautrix.DefaultUserAgent,
Live: true,
Ready: false,
}
}

Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions appservice/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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("{}"))
}

0 comments on commit 386ac2e

Please sign in to comment.