Add state caching and invalidation to service type
This required a change in the event system to add an "activity" field. This is meant to be generic in the case that there is more than one need for it, but at the moment, allows a poke to tell that it is a poke in response to an apply that just finished, instead of a regular poke or backpoke in which all that matters is timestamp updates, because there wasn't any actual work done (since that state was okay).
This commit is contained in:
22
service.go
22
service.go
@@ -82,9 +82,10 @@ func (obj *ServiceType) Watch() {
|
||||
|
||||
var service = fmt.Sprintf("%v.service", obj.Name) // systemd name
|
||||
var send = false // send event?
|
||||
var invalid = false // does the service exist or not?
|
||||
var previous bool // previous invalid value
|
||||
set := conn.NewSubscriptionSet() // no error should be returned
|
||||
var dirty = false
|
||||
var invalid = false // does the service exist or not?
|
||||
var previous bool // previous invalid value
|
||||
set := conn.NewSubscriptionSet() // no error should be returned
|
||||
subChannel, subErrors := set.Subscribe()
|
||||
var activeSet = false
|
||||
|
||||
@@ -112,6 +113,7 @@ func (obj *ServiceType) Watch() {
|
||||
|
||||
if previous != invalid { // if invalid changed, send signal
|
||||
send = true
|
||||
dirty = true
|
||||
}
|
||||
|
||||
if invalid {
|
||||
@@ -133,6 +135,9 @@ func (obj *ServiceType) Watch() {
|
||||
if ok := obj.ReadEvent(&event); !ok {
|
||||
return // exit
|
||||
}
|
||||
if event.GetActivity() {
|
||||
dirty = true
|
||||
}
|
||||
send = true
|
||||
case _ = <-TimeAfterOrBlock(obj.ctimeout):
|
||||
obj.SetConvergedState(typeConvergedTimeout)
|
||||
@@ -166,6 +171,7 @@ func (obj *ServiceType) Watch() {
|
||||
log.Printf("Service[%v]->Stopped", service)
|
||||
}
|
||||
send = true
|
||||
dirty = true
|
||||
|
||||
case err := <-subErrors:
|
||||
obj.SetConvergedState(typeConvergedNil) // XXX ?
|
||||
@@ -178,12 +184,19 @@ func (obj *ServiceType) Watch() {
|
||||
if ok := obj.ReadEvent(&event); !ok {
|
||||
return // exit
|
||||
}
|
||||
if event.GetActivity() {
|
||||
dirty = true
|
||||
}
|
||||
send = true
|
||||
}
|
||||
}
|
||||
|
||||
if send {
|
||||
send = false
|
||||
if dirty {
|
||||
dirty = false
|
||||
obj.isStateOK = false // something made state dirty
|
||||
}
|
||||
Process(obj) // XXX: rename this function
|
||||
}
|
||||
|
||||
@@ -191,6 +204,9 @@ func (obj *ServiceType) Watch() {
|
||||
}
|
||||
|
||||
func (obj *ServiceType) StateOK() bool {
|
||||
if obj.isStateOK { // cache the state
|
||||
return true
|
||||
}
|
||||
|
||||
if !util.IsRunningSystemd() {
|
||||
log.Fatal("Systemd is not running.")
|
||||
|
||||
Reference in New Issue
Block a user