diff --git a/src/udi/config/config.go b/src/udi/config/config.go index 32b09d1..a82f09f 100644 --- a/src/udi/config/config.go +++ b/src/udi/config/config.go @@ -21,6 +21,9 @@ type ConfigT struct { DatabaseConnStr string `json:"databaseConnStr"` Attributes map[string]string `json:"attributes"` } `json:"handlers"` + Archiver struct { + Dir string `json:"dir"` + } } var Config ConfigT diff --git a/src/udi/dispatcher/dispatcher.go b/src/udi/dispatcher/dispatcher.go index 3925edd..9fcc490 100644 --- a/src/udi/dispatcher/dispatcher.go +++ b/src/udi/dispatcher/dispatcher.go @@ -1,6 +1,8 @@ package dispatcher import "log" +import "time" +import "os" import "udi/mqtt" import "udi/config" import "udi/handlers/handler" @@ -26,9 +28,24 @@ func InitDispatcher() { } func archiver() { + archivingRootDir := config.Config.Archiver.Dir + currentArchivingDir := "" + lastArchivingDir := "" + for { select { case _ = <- archiverChannel: + currentTime := time.Now() + currentDateStr := currentTime.Format("2006/01/02") + currentArchivingDir := archivingRootDir + "/" + currentDateStr + if currentArchivingDir != lastArchivingDir { + err := os.MkdirAll(currentArchivingDir, 0755) + if err := nil { + log.Printf("Unable to create archiving dir %s", currentArchivingDir) + } + lastArchivingDir = currentArchivingDir + } + archivingFilename := currentArchivingDir + "/" + string(currentTime.Hour()) + "/" log.Printf("Archiving message") } }