mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
45 lines
735 B
Go
45 lines
735 B
Go
package apps
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/apex/log"
|
|
"github.com/crawlab-team/go-trace"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func Start(app App) {
|
|
start(app)
|
|
}
|
|
|
|
func start(app App) {
|
|
app.Init()
|
|
go app.Start()
|
|
app.Wait()
|
|
app.Stop()
|
|
}
|
|
|
|
func DefaultWait() {
|
|
quit := make(chan os.Signal, 1)
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
<-quit
|
|
}
|
|
|
|
func initModule(name string, fn func() error) (err error) {
|
|
if err := fn(); err != nil {
|
|
log.Error(fmt.Sprintf("init %s error: %s", name, err.Error()))
|
|
_ = trace.TraceError(err)
|
|
panic(err)
|
|
}
|
|
log.Info(fmt.Sprintf("initialized %s successfully", name))
|
|
return nil
|
|
}
|
|
|
|
func initApp(name string, app App) {
|
|
_ = initModule(name, func() error {
|
|
app.Init()
|
|
return nil
|
|
})
|
|
}
|