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.

96 lines
2.6 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import (
"forge.chapril.org/losyme/application"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/losyme/minikit"
"forge.chapril.org/dune/dune/internal/components"
)
type Application struct {
minikit *minikit.Kit
components *components.Components
cmdLine *cmdLine
demo *demo
}
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 {
return app.minikit.RunServer(
func() error { // build..........................................................................................
if fn := app.cmdLine.runAfter; fn != nil {
if err := fn(); err != nil {
return errors.WithMessage(err, "runAfter") /////////////////////////////////////////////////////////
}
}
if err := app.storage(); err != nil {
return errors.WithMessage(err, "storage") //////////////////////////////////////////////////////////////
}
if err := app.model(); err != nil {
return errors.WithMessage(err, "model") ////////////////////////////////////////////////////////////////
}
if err := app.API(); err != nil {
return errors.WithMessage(err, "API") //////////////////////////////////////////////////////////////////
}
if app.cmdLine.demo {
if err := app.setupDemo(); err != nil {
return errors.WithMessage(err, "demo") /////////////////////////////////////////////////////////////
}
}
app.components.Scheduler.Start()
return nil
},
func() { // atEnd................................................................................................
<-app.components.Scheduler.Stop().Done()
},
)
}
/*
######################################################################################################## @(°_°)@ #######
*/