-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (53 loc) · 1.27 KB
/
main.go
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
63
64
65
66
67
package main
import (
"context"
"os"
"github.com/bcc-code/mediabank-bridge/log"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
)
func (h *handlers) manager(ctx context.Context) {
for {
if ctx.Err() != nil {
return
}
if len(h.queuedJobs) > 0 {
job := h.queuedJobs[0]
h.queuedJobs = h.queuedJobs[1:]
h.processedJobs = append(h.processedJobs, job)
if len(h.processedJobs) > 10 {
h.processedJobs = h.processedJobs[len(h.processedJobs)-10:]
}
runJob(job)
continue
}
log.L.Info().Msg("Queue done. Waiting")
select {
case <-ctx.Done():
return
case <-h.queueChan:
log.L.Info().Msg("New job")
continue
}
}
}
func main() {
log.ConfigureGlobalLogger(zerolog.DebugLevel)
handler := NewHandlers()
r := gin.Default()
r.GET("/stats", handler.Stats)
r.GET("/smi", handler.Smi)
transcription := r.Group("/transcription/")
transcription.POST("/job", handler.SubmitJob)
transcription.GET("/jobs", handler.ListJobs)
transcription.DELETE("/job/:id", handler.DeleteJob)
transcription.GET("/job/:id", handler.GetJob)
port := os.Getenv("PORT")
if port == "" {
port = "8888"
}
managerContext, cancelManager := context.WithCancel(context.Background())
go handler.manager(managerContext)
r.Run(":" + port)
cancelManager()
}