func (h *Server) PostLogs(ctx context.Context, w http.ResponseWriter, r *http.Request) error { a, err := findApp(ctx, h) if err != nil { return err } var form PostLogsForm // We ignore the EOF error for backwards compatability with the "emp" // command that doesn't support providing a duration. ignoreEOF := true if err := DecodeRequest(r, &form, ignoreEOF); err != nil { return err } rw := streamhttp.StreamingResponseWriter(w) // Prevent the ELB idle connection timeout to close the connection. defer close(streamhttp.Heartbeat(rw, 10*time.Second)) err = h.StreamLogs(a, rw, time.Duration(form.Duration)) if err != nil { return err } return nil }
func (h *PostProcess) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { var form PostProcessForm a, err := findApp(ctx, h) if err != nil { return err } if err := Decode(r, &form); err != nil { return err } opts := empire.RunOpts{ User: UserFromContext(ctx), App: a, Command: form.Command, Env: form.Env, } if form.Attach { inStream, outStream, err := hijackServer(w) if err != nil { return err } defer closeStreams(inStream, outStream) fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.empire.raw-stream\r\n\r\n") // Prevent the ELB idle connection timeout to close the connection. defer close(streamhttp.Heartbeat(outStream, 10*time.Second)) opts.Input = inStream opts.Output = outStream if err := h.Run(ctx, opts); err != nil { fmt.Fprintf(outStream, "%v", err) return nil } } else { if err := h.Run(ctx, opts); err != nil { return err } dyno := &heroku.Dyno{ Name: "run", Command: form.Command, CreatedAt: timex.Now(), } w.WriteHeader(201) return Encode(w, dyno) } return nil }
func (d *TugboatDeployer) Deploy(ctx context.Context, event events.Deployment, out io.Writer) error { opts := tugboat.NewDeployOptsFromEvent(event) // Perform the deployment, wrapped in Deploy. This will automatically // write hte logs to tugboat and update the deployment status when this // function returns. _, err := d.client.Deploy(ctx, opts, provider(func(ctx context.Context, _ *tugboat.Deployment, w io.Writer) error { defer close(streamhttp.Heartbeat(w, 10*time.Second)) // Write logs to both tugboat as well as the writer we were // provided (probably stdout). w = io.MultiWriter(w, out) return d.deployer.Deploy(ctx, event, w) })) return err }
func (h *PostLogs) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { a, err := findApp(ctx, h) if err != nil { return err } rw := streamhttp.StreamingResponseWriter(w) // Prevent the ELB idle connection timeout to close the connection. defer close(streamhttp.Heartbeat(rw, 10*time.Second)) err = h.StreamLogs(a, rw) if err != nil { return err } return nil }
func (h *PostProcess) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error { var form PostProcessForm a, err := findApp(ctx, h) if err != nil { return err } m, err := findMessage(r) if err != nil { return err } if err := Decode(r, &form); err != nil { return err } command, err := empire.ParseCommand(form.Command) if err != nil { return err } opts := empire.RunOpts{ User: UserFromContext(ctx), App: a, Command: command, Env: form.Env, Constraints: form.Size, Message: m, } if form.Attach { header := http.Header{} header.Set("Content-Type", "application/vnd.empire.raw-stream") stream := &hijack.HijackReadWriter{ Response: w, Header: header, } defer stream.Close() // Prevent the ELB idle connection timeout to close the connection. defer close(streamhttp.Heartbeat(stream, 10*time.Second)) opts.Input = stream opts.Output = stream if err := h.Run(ctx, opts); err != nil { if stream.Hijacked { fmt.Fprintf(stream, "%v\r", err) return nil } return err } } else { if err := h.Run(ctx, opts); err != nil { return err } dyno := &heroku.Dyno{ Name: "run", Command: form.Command, CreatedAt: timex.Now(), } w.WriteHeader(201) return Encode(w, dyno) } return nil }