sermoni

"Service monitor" / cronjob status service
Log | Files | Refs

commit 3631c6e47818399e9b6fc2759b09bde2bdcfc12a
parent 8395f865cd4f0f1ac77aa6e15fef8f74b3b5f0d8
Author: Vetle Haflan <vetle@haflan.dev>
Date:   Tue, 14 Apr 2020 01:22:20 +0200

Fix maxevents, and use numbers instead of strings where needed

Diffstat:
Minternal/services/services.go | 15+++++++++++++++
Mui/src/Services.vue | 8++++----
2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/internal/services/services.go b/internal/services/services.go @@ -150,6 +150,10 @@ func Add(service *Service) error { if err = sb.Put(keyServicePeriod, []byte(periodStr)); err != nil { return err } + maxEventsStr := strconv.FormatUint(service.MaxNumberEvents, 10) + if err = sb.Put(keyServiceMaxEvents, []byte(maxEventsStr)); err != nil { + return err + } // Put an entry in the service-tokens bucket to map the token to the service return stb.Put([]byte(service.Token), serviceID) @@ -183,6 +187,17 @@ func (service *Service) fromBucket(id []byte, sb *bbolt.Bucket) { service.ExpectationPeriod = 0 } } + if maxevents := sb.Get(keyServiceMaxEvents); maxevents != nil { + // Quick fix: Convert to string, then int + // Uses default value 0 if an error occurs + intMaxEvents, err := strconv.ParseUint(string(maxevents), 10, 64) + if err == nil { + service.MaxNumberEvents = intMaxEvents + } else { + log.Println("Couldn't convert max num events to int for service") + service.MaxNumberEvents = 0 + } + } } // get returns the service structure associated with the []byte-formatted service ID diff --git a/ui/src/Services.vue b/ui/src/Services.vue @@ -5,17 +5,17 @@ <input type="text" :value="service.token"> <input type="text" :value="service.name"> <input type="text" :value="service.description"> - <input type="text" :value="service.period"> - <input type="text" :value="service.maxevents"> + <input type="number" :value="service.period"> + <input type="number" :value="service.maxevents"> </div> <input type="text" v-model="newService.token" placeholder="Token"> <input type="text" v-model="newService.name" placeholder="Name"> <input type="text" v-model="newService.description" placeholder="Description"> - <input type="text" v-model="newService.period" + <input type="number" v-model.number="newService.period" placeholder="Expectation Period"> - <input type="text" v-model="newService.maxevents" + <input type="number" v-model.number="newService.maxevents" placeholder="Max number of events"> <button @click="addService">Add service</button>