Gestionnaire de jobs et workflows
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dune/internal/application/application.go

111 lines
2.4 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import (
"forge.chapril.org/losyme/application"
"forge.chapril.org/losyme/minikit"
"forge.chapril.org/losyme/util"
"forge.chapril.org/dune/dune/internal/api"
"forge.chapril.org/dune/dune/internal/components"
)
type Application struct {
minikit *minikit.Kit
components *components.Components
cmdLine *cmdLine
}
func New(name, version, builtAt string, args []string) *Application {
app := &Application{
cmdLine: &cmdLine{},
}
kit := minikit.New(&minikit.Config{
Application: application.New(name, version, builtAt, "job and workflow management server"),
Components: []string{
"cmdline",
"config",
"crypto",
"logger",
"router",
"scheduler",
"server",
},
CmdLineArgs: args,
CmdLineInit: app.cmdlineInitialize,
ConfigInit: app.configInitialize,
SchedulerCb: app.eventManager,
})
app.minikit = kit
cs := &components.Components{
Components: kit.Components,
}
app.components = cs
return app
}
func (app *Application) run() error {
if err := app.minikit.Build(); err != nil {
return err
}
if run := app.cmdLine.runAfter; run != nil {
return run()
}
if err := app.storage(); err != nil {
return err
}
if err := app.model(); err != nil {
return err
}
api.Setup(app.components)
app.components.Scheduler.Start()
group, endCh := util.WaitAppEnd(func() {
<-app.components.Scheduler.Stop().Done()
ctx, cancel := util.CtxWithTimeout(10)
defer cancel()
_ = app.components.Server.Shutdown(ctx) //AFINIR
})
err := app.components.Server.ListenAndServe()
close(endCh)
group.Wait()
return err
}
func (app *Application) Run() error {
err := app.run()
if logger := app.components.Logger; logger != nil {
if err != nil {
logger.Fatal(err.Error()) //////////////////////////////////////////////////////////////////////////////////
}
logger.Close()
}
return app.components.Application.OnError(err) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}
/*
######################################################################################################## @(°_°)@ #######
*/