zdravko/pkg/temporal/temporal.go

62 lines
1 KiB
Go
Raw Normal View History

2024-02-16 21:31:00 +00:00
package temporal
import (
"log/slog"
"github.com/mentos1386/zdravko/internal/config"
2024-02-16 21:31:00 +00:00
"github.com/temporalio/ui-server/v2/server"
t "go.temporal.io/server/temporal"
)
type Temporal struct {
server t.Server
uiServer *server.Server
}
func NewTemporal(cfg *config.TemporalConfig) (*Temporal, error) {
logger := slog.Default()
2024-02-16 21:31:00 +00:00
serverConfig := NewServerConfig(cfg)
tokenKeyProvider := TokenKeyProvider{config: cfg}
server, err := NewServer(logger, serverConfig, &tokenKeyProvider)
2024-02-16 21:31:00 +00:00
if err != nil {
return nil, err
}
uiConfig := NewUiConfig(cfg)
uiServer, err := NewUiServer(uiConfig)
if err != nil {
return nil, err
}
return &Temporal{
server: server,
uiServer: uiServer,
}, nil
}
func (t *Temporal) Name() string {
return "Temporal UI and Server"
}
func (t *Temporal) Start() error {
go func() {
err := t.uiServer.Start()
if err != nil {
panic(err)
}
}()
return t.server.Start()
}
func (t *Temporal) Stop() error {
t.uiServer.Stop()
2024-02-16 21:31:00 +00:00
err := t.server.Stop()
if err != nil {
return err
}
return nil
}