Use workers for module failure mirroring and fix mirror looping

This commit is contained in:
Daniel 2021-05-17 16:05:50 +02:00
parent 5c87029991
commit ae13d87aed
2 changed files with 13 additions and 5 deletions
modules
notifications

View file

@ -139,7 +139,7 @@ func (m *Module) setFailure(status uint8, id, title, msg string) {
// Propagate failure status.
if failureUpdateNotifyFuncReady.IsSet() {
m.newTask("failure status updater", func(context.Context, *Task) error {
m.RunWorker("failure status updater", func(context.Context) error {
// Only use data in worker that won't change anymore.
// Resolve previous failure state if available.
@ -151,7 +151,7 @@ func (m *Module) setFailure(status uint8, id, title, msg string) {
failureUpdateNotifyFunc(status, id, title, msg)
return nil
}).QueuePrioritized()
})
}
}
@ -181,11 +181,11 @@ func (m *Module) Resolve(failureID string) {
// Propagate failure status.
if failureUpdateNotifyFuncReady.IsSet() {
m.newTask("failure status updater", func(context.Context, *Task) error {
m.RunWorker("failure status updater", func(context.Context) error {
// Only use data in worker that won't change anymore.
failureUpdateNotifyFunc(FailureNone, resolveFailureID, "", "")
return nil
}).QueuePrioritized()
})
}
}

View file

@ -70,7 +70,13 @@ func mirrorModuleStatus(moduleFailure uint8, id, title, msg string) {
// The notification already exists.
// Check if we should delete it.
if moduleFailure == modules.FailureNone {
if moduleFailure == modules.FailureNone && !n.Meta().IsDeleted() {
// Remove belongsTo, as the deletion was already triggered by the module itself.
n.Lock()
n.belongsTo = nil
n.Unlock()
n.Delete()
}
@ -92,6 +98,8 @@ func mirrorModuleStatus(moduleFailure uint8, id, title, msg string) {
}
switch moduleFailure {
case modules.FailureNone:
return
case modules.FailureHint:
n.Type = Info
n.AvailableActions = nil