Skip to content

Commit

Permalink
Merge pull request #1103 from weaveworks/994-pipes-check-endpoint
Browse files Browse the repository at this point in the history
Add pipe/{pipeID}/check endpoint
  • Loading branch information
Alfonso Acosta committed Mar 3, 2016
2 parents 3f3adae + b9393e9 commit fa4ab48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 16 additions & 0 deletions app/pipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (

// RegisterPipeRoutes registers the pipe routes
func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) {
router.Methods("GET").
Path("/api/pipe/{pipeID}/check").
HandlerFunc(requestContextDecorator(checkPipe(pr, UIEnd)))

router.Methods("GET").
Path("/api/pipe/{pipeID}").
HandlerFunc(requestContextDecorator(handlePipeWs(pr, UIEnd)))
Expand All @@ -25,6 +29,18 @@ func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) {
HandlerFunc(requestContextDecorator(deletePipe(pr)))
}

func checkPipe(pr PipeRouter, end End) CtxHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["pipeID"]
_, _, ok := pr.Get(ctx, id, end)
if !ok {
w.WriteHeader(http.StatusNoContent)
return
}
pr.Release(ctx, id, end)
}
}

func handlePipeWs(pr PipeRouter, end End) CtxHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["pipeID"]
Expand Down
16 changes: 8 additions & 8 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,21 @@ export function deletePipe(pipeId) {
}

export function getPipeStatus(pipeId) {
const url = `/api/pipe/${encodeURIComponent(pipeId)}`;
const url = `/api/pipe/${encodeURIComponent(pipeId)}/check`;
reqwest({
method: 'GET',
url: url,
success: function(res) {
log('ERROR: expected responses: [400, 404]. Got:', res);
},
error: function(err) {
log('ERROR: unexpected response:', err);
},
success: function(res) {
const status = {
400: 'PIPE_ALIVE',
404: 'PIPE_DELETED'
}[err.status];
200: 'PIPE_ALIVE',
204: 'PIPE_DELETED'
}[res.status];

if (!status) {
log('Unexpected pipe status:', err.status);
log('Unexpected pipe status:', res.status);
return;
}

Expand Down

0 comments on commit fa4ab48

Please sign in to comment.