Ocean/Log/Scheduler.go

53 lines
1.4 KiB
Go
Raw Normal View History

package Log
import (
"github.com/SommerEngineering/Ocean/Log/Meta"
"time"
)
2015-06-17 15:44:52 +00:00
/*
The scheduler function which runs at a own thread.
Pleae note: The scheduler is the consumer for the logging channel.
*/
func scheduler(logBuffer chan Meta.Entry) {
LogShort(senderName, Meta.CategorySYSTEM, Meta.LevelINFO, Meta.MessageNameSTARTUP, `The scheduler runs now.`)
var stopNextTime = false
2015-06-17 15:44:52 +00:00
// Endless loop:
for {
2015-06-17 15:44:52 +00:00
// Enable the loop to stop:
if stopNextTime {
break
}
2015-06-17 15:44:52 +00:00
// Read one entry from the buffer (channel):
nextEntry, ok := <-logBuffer
2015-06-17 15:44:52 +00:00
// Case: The channel was closed.
if !ok {
2015-06-17 15:44:52 +00:00
// Create a log message for this event.
stopNextTime = true
nextEntry = Meta.Entry{}
nextEntry.Project = projectName
nextEntry.Time = time.Now().UTC()
nextEntry.Sender = senderName
nextEntry.Category = Meta.CategorySYSTEM
nextEntry.Level = Meta.LevelWARN
nextEntry.Severity = Meta.SeverityCritical
nextEntry.Impact = Meta.ImpactNone
nextEntry.MessageName = Meta.MessageNameCOMMUNICATION
nextEntry.MessageDescription = `The logging channel was closed!`
}
2015-06-17 15:44:52 +00:00
// Queue the log event for the delivery to the devices:
deviceDelay(nextEntry)
}
2015-06-17 15:44:52 +00:00
// Exit the scheduler. Send the signal.
LogFull(senderName, Meta.CategorySYSTEM, Meta.LevelWARN, Meta.SeverityCritical, Meta.ImpactNone, Meta.MessageNameSHUTDOWN, `The scheduler is down now.`)
schedulerExitSignal <- true
}