the-anna-project / annad

The annad package implements a command line tool to run the neural network of the anna project.
https://anna.earth
BSD 3-Clause "New" or "Revised" License
43 stars 7 forks source link

add info writer to storage implementations #259

Open xh3b4sd opened 7 years ago

xh3b4sd commented 7 years ago

Storages are not used outside of services. The annad object used to write state information to the storage. This functionality should be added to storage implementations so that this is provided out of the box. Therefore Boot should be added to the Storage interface.

// writeStateInfo writes state information to the configured general storage.
// The information look like this.
//
//     "time":       "16/03/27 21:14:35"
//     "version":    "84ehdv0"
//
func (a *annad) writeStateInfo() {
    a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call writeStateInfo")

    err := a.Storage().General().Set("version", version)
    panicOnError(err)

    for {
        dateTime := time.Now().Format("06/01/02 15:04:05")
        err := a.Storage().General().Set("time", dateTime)
        if err != nil {
            a.Log.WithTags(spec.Tags{C: nil, L: "E", O: a, V: 4}, "%#v", maskAny(err))
        }

        time.Sleep(5 * time.Second)
    }
}