forked from brody192/locomotive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.go
More file actions
62 lines (50 loc) · 1.58 KB
/
handlers.go
File metadata and controls
62 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"log/slog"
"sync/atomic"
"github.com/brody192/locomotive/internal/logger"
"github.com/brody192/locomotive/internal/railway/subscribe/environment_logs"
"github.com/brody192/locomotive/internal/railway/subscribe/http_logs"
"github.com/brody192/locomotive/internal/webhook"
)
func handleDeployLogsAsync(ctx context.Context, deployLogsProcessed *atomic.Int64, serviceLogTrack chan []environment_logs.EnvironmentLogWithMetadata) {
go func() {
for {
select {
case <-ctx.Done():
return
case logs := <-serviceLogTrack:
if serializedLogs, err := webhook.SendDeployLogsWebhook(logs); err != nil {
attrs := []any{logger.ErrAttr(err)}
if serializedLogs != nil {
attrs = append(attrs, slog.String("serialized_logs", string(serializedLogs)))
}
logger.Stderr.Error("error sending deploy logs webhook(s)", attrs...)
continue
}
deployLogsProcessed.Add(int64(len(logs)))
}
}
}()
}
func handleHttpLogsAsync(ctx context.Context, httpLogsProcessed *atomic.Int64, httpLogTrack chan []http_logs.DeploymentHttpLogWithMetadata) {
go func() {
for {
select {
case <-ctx.Done():
return
case logs := <-httpLogTrack:
if serializedLogs, err := webhook.SendHttpLogsWebhook(logs); err != nil {
attrs := []any{logger.ErrAttr(err)}
if serializedLogs != nil {
attrs = append(attrs, slog.String("serialized_logs", string(serializedLogs)))
}
logger.Stderr.Error("error sending http logs webhook(s)", attrs...)
continue
}
httpLogsProcessed.Add(int64(len(logs)))
}
}
}()
}