Skip to content

Commit

Permalink
app startup info improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Nov 3, 2018
1 parent 91f1696 commit cd7b920
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
17 changes: 6 additions & 11 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"aahframe.work/essentials"
"aahframe.work/internal/util"
"aahframe.work/log"
)

const (
Expand Down Expand Up @@ -154,7 +153,10 @@ func (a *Application) OnPostShutdown(ecb EventCallbackFunc, priority ...int) {
// hot-reload and re-initialize completes without an error otherwise it won't be
// published.
func (a *Application) OnConfigHotReload(ecb EventCallbackFunc, priority ...int) {
a.subcribeAppEvent(EventOnConfigHotReload, ecb, priority)
a.SubscribeEvent(EventOnConfigHotReload, EventCallback{
Callback: ecb,
priority: parsePriority(priority),
})
}

func (a *Application) subcribeAppEvent(eventName string, ecb EventCallbackFunc, priority []int) {
Expand Down Expand Up @@ -224,8 +226,7 @@ func (es *EventStore) Publish(e *Event) {
if !es.IsEventExists(e.Name) {
return
}

es.a.Log().Debugf("Event [%s] published in asynchronous mode", e.Name)
es.a.Log().Debugf("Publishing event '%s' in asynchronous mode", e.Name)
for idx, ec := range es.subscribers[e.Name] {
if ec.CallOnce {
if !ec.published {
Expand All @@ -250,13 +251,7 @@ func (es *EventStore) PublishSync(e *Event) {
if !es.IsEventExists(e.Name) {
return
}

if es.a.Log() == nil {
log.Debugf("Event [%s] publishing in synchronous mode", e.Name)
} else {
es.a.Log().Debugf("Event [%s] publishing in synchronous mode", e.Name)
}

es.a.Log().Debugf("Publishing event '%s' in synchronous mode", e.Name)
for idx, ec := range es.subscribers[e.Name] {
if ec.CallOnce {
if !ec.published {
Expand Down
17 changes: 9 additions & 8 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ func (a *Application) Start() {
a.Log().Infof("App i18n Locales: %s", strings.Join(a.I18n().Locales(), ", "))
}

if a.Log().IsLevelDebug() {
for event := range a.EventStore().subscribers {
for _, c := range a.EventStore().subscribers[event] {
a.Log().Debugf("Event: %s (callback=%s priority=%v)", event, ess.GetFunctionInfo(c.Callback).QualifiedName, c.priority)
}
}
}

if !a.IsProfile(settings.DefaultEnvProfile) {
a.Log().Infof("App Config Hot-Reload Enabled: %v", a.settings.HotReloadEnabled)
if a.settings.HotReloadEnabled {
Expand All @@ -90,6 +82,15 @@ func (a *Application) Start() {
}
a.Log().Infof("App Shutdown Grace Timeout: %s", a.settings.ShutdownGraceTimeStr)

if a.Log().IsLevelDebug() {
a.Log().Debug("Subscribed event callbacks")
for _, event := range []string{EventOnInit, EventOnStart, EventOnPreShutdown, EventOnPostShutdown, EventOnConfigHotReload} {
for _, c := range a.EventStore().subscribers[event] {
a.Log().Debugf("Event: %s (callback=%s priority=%v)", event, ess.GetFunctionInfo(c.Callback).QualifiedName, c.priority)
}
}
}

// Publish `OnStart` event
a.EventStore().sortAndPublishSync(&Event{Name: EventOnStart})

Expand Down

0 comments on commit cd7b920

Please sign in to comment.