Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

activator: send slog to requestor

+42 -1
+1
.gitignore
··· 46 46 dev-server.json 47 47 .erlang-history/ 48 48 /sower-activator 49 + cmd/sower-activator/sower-activator 49 50 .direnv 50 51 .workspaces/ 51 52 .gocache/
+40
cmd/sower-activator/handler.go
··· 2 2 3 3 import ( 4 4 "bufio" 5 + "context" 5 6 "encoding/json" 6 7 "fmt" 7 8 "io" ··· 135 136 return nil 136 137 } 137 138 139 + // callbackSlogHandler tees slog records to an OutputCallback in addition to 140 + // delegating to an underlying handler (e.g. the stderr text handler). 141 + type callbackSlogHandler struct { 142 + base slog.Handler 143 + callback OutputCallback 144 + } 145 + 146 + func (h *callbackSlogHandler) Enabled(ctx context.Context, level slog.Level) bool { 147 + return h.base.Enabled(ctx, level) 148 + } 149 + 150 + func (h *callbackSlogHandler) Handle(ctx context.Context, r slog.Record) error { 151 + var sb strings.Builder 152 + sb.WriteString("[activator] ") 153 + sb.WriteString(r.Level.String()) 154 + sb.WriteString(" ") 155 + sb.WriteString(r.Message) 156 + r.Attrs(func(a slog.Attr) bool { 157 + sb.WriteString(" ") 158 + sb.WriteString(a.String()) 159 + return true 160 + }) 161 + h.callback(sb.String(), r.Level >= slog.LevelError) 162 + return h.base.Handle(ctx, r) 163 + } 164 + 165 + func (h *callbackSlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler { 166 + return &callbackSlogHandler{base: h.base.WithAttrs(attrs), callback: h.callback} 167 + } 168 + 169 + func (h *callbackSlogHandler) WithGroup(name string) slog.Handler { 170 + return &callbackSlogHandler{base: h.base.WithGroup(name), callback: h.callback} 171 + } 172 + 138 173 // executeRequest runs the request action and streams output. 139 174 func (h *ConnectionHandler) executeRequest(req *Request) int { 140 175 outputCallback := func(line string, isError bool) { ··· 148 183 Data: line, 149 184 }) 150 185 } 186 + 187 + // Tee activator slog messages into the output stream for this request. 188 + orig := slog.Default() 189 + slog.SetDefault(slog.New(&callbackSlogHandler{base: orig.Handler(), callback: outputCallback})) 190 + defer slog.SetDefault(orig) 151 191 152 192 var ( 153 193 exitCode int
+1 -1
justfile
··· 87 87 start: dev-services start-all 88 88 89 89 start-all: 90 - iex --sname dev1 -S mix phx.server 90 + nix shell ".#activator" -c iex --sname dev1 -S mix phx.server 91 91 92 92 start-agent: 93 93 nix shell ".#activator" -c iex --sname agent1 --dot-iex ./.iex-agent.exs -S mix run --no-start