-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor temporal and make it work on fly
- Loading branch information
1 parent
b516c97
commit 4a9d684
Showing
13 changed files
with
161 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"go.temporal.io/server/common/config" | ||
"go.temporal.io/server/schema/sqlite" | ||
"go.temporal.io/server/temporal" | ||
|
||
"code.tjo.space/mentos1386/zdravko/internal" | ||
t "code.tjo.space/mentos1386/zdravko/pkg/temporal" | ||
|
||
"go.temporal.io/server/common/authorization" | ||
tlog "go.temporal.io/server/common/log" | ||
|
||
uiserver "github.com/temporalio/ui-server/v2/server" | ||
uiconfig "github.com/temporalio/ui-server/v2/server/config" | ||
uiserveroptions "github.com/temporalio/ui-server/v2/server/server_options" | ||
) | ||
|
||
func backendServer() { | ||
cfg := t.NewConfig() | ||
|
||
logger := tlog.NewZapLogger(tlog.BuildZapLogger(tlog.Config{ | ||
Stdout: true, | ||
Level: "info", | ||
OutputFile: "", | ||
})) | ||
|
||
sqlConfig := cfg.Persistence.DataStores[t.PersistenceStoreName].SQL | ||
|
||
// Apply migrations if file does not already exist | ||
if _, err := os.Stat(sqlConfig.DatabaseName); os.IsNotExist(err) { | ||
// Check if any of the parent dirs are missing | ||
dir := filepath.Dir(sqlConfig.DatabaseName) | ||
if _, err := os.Stat(dir); err != nil { | ||
log.Fatal(err) | ||
} | ||
func backendServer(config *internal.Config) { | ||
serverConfig := t.NewServerConfig(config) | ||
|
||
if err := sqlite.SetupSchema(sqlConfig); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// Pre-create namespaces | ||
var namespaces []*sqlite.NamespaceConfig | ||
for _, ns := range []string{"default"} { | ||
namespaces = append(namespaces, sqlite.NewNamespaceConfig(cfg.ClusterMetadata.CurrentClusterName, ns, false)) | ||
} | ||
if err := sqlite.CreateNamespaces(sqlConfig, namespaces...); err != nil { | ||
log.Fatal(err) | ||
server, err := t.NewServer(serverConfig) | ||
if err != nil { | ||
log.Fatalf("Unable to create server: %v", err) | ||
} | ||
|
||
authorizer, err := authorization.GetAuthorizerFromConfig(&cfg.Global.Authorization) | ||
err = server.Start() | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Fatalf("Unable to start server: %v", err) | ||
} | ||
|
||
claimMapper, err := authorization.GetClaimMapperFromConfig(&cfg.Global.Authorization, logger) | ||
err = server.Stop() | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Fatalf("Unable to stop server: %v", err) | ||
} | ||
} | ||
|
||
ctx := context.Background() | ||
interruptChan := make(chan interface{}, 1) | ||
go func() { | ||
if doneChan := ctx.Done(); doneChan != nil { | ||
s := <-doneChan | ||
interruptChan <- s | ||
} else { | ||
s := <-temporal.InterruptCh() | ||
interruptChan <- s | ||
} | ||
}() | ||
func frontendServer(config *internal.Config) { | ||
uiConfig := t.NewUiConfig(config) | ||
|
||
temporal, err := temporal.NewServer( | ||
temporal.WithConfig(cfg), | ||
temporal.ForServices(temporal.DefaultServices), | ||
temporal.WithLogger(logger), | ||
temporal.WithAuthorizer(authorizer), | ||
temporal.WithClaimMapper(func(cfg *config.Config) authorization.ClaimMapper { | ||
return claimMapper | ||
}), | ||
temporal.InterruptOn(interruptChan), | ||
) | ||
uiServer, err := t.NewUiServer(uiConfig) | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Fatalf("Unable to create UI server: %v", err) | ||
} | ||
|
||
log.Println("Starting temporal server") | ||
if err := temporal.Start(); err != nil { | ||
panic(err) | ||
} | ||
err = temporal.Stop() | ||
err = uiServer.Start() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
} | ||
|
||
func frontendServer() { | ||
cfg := &uiconfig.Config{ | ||
Host: "0.0.0.0", | ||
Port: 8223, | ||
TemporalGRPCAddress: "localhost:7233", | ||
EnableUI: true, | ||
PublicPath: "/temporal", | ||
Codec: uiconfig.Codec{ | ||
Endpoint: "", | ||
}, | ||
CORS: uiconfig.CORS{ | ||
CookieInsecure: true, | ||
}, | ||
log.Fatalf("Unable to start UI server: %v", err) | ||
} | ||
|
||
server := uiserver.NewServer(uiserveroptions.WithConfigProvider(cfg)) | ||
|
||
log.Println("Starting temporal ui server") | ||
if err := server.Start(); err != nil { | ||
panic(err) | ||
} | ||
server.Stop() | ||
uiServer.Stop() | ||
} | ||
|
||
func main() { | ||
config := internal.NewConfig() | ||
|
||
go func() { | ||
frontendServer() | ||
frontendServer(config) | ||
}() | ||
backendServer() | ||
backendServer(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.