resources: Remove SetWatching/IsWatching code from Watch

This removes some boilerplate from the Watch methods which can be baked
into the engine instead.

This code should be checked for races and locks to make sure we only
start resources when it makes sense to.
This commit is contained in:
James Shubin
2016-12-11 23:00:20 -05:00
parent af47511d58
commit 067932aebf
13 changed files with 5 additions and 57 deletions

View File

@@ -289,6 +289,9 @@ func (g *Graph) Worker(v *Vertex) error {
// the Watch() function about which graph it is
// running on, which isolates things nicely...
obj := v.Res
// TODO: is there a better system for the `Watching` flag?
obj.SetWatching(true)
defer obj.SetWatching(false)
processChan := make(chan event.Event)
go func() {
running := false

View File

@@ -110,11 +110,6 @@ func (obj *ExecRes) BufioChanScanner(scanner *bufio.Scanner) (chan string, chan
// Watch is the primary listener for this resource and it outputs events.
func (obj *ExecRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
var send = false // send event?

View File

@@ -141,11 +141,6 @@ func (obj *FileRes) Validate() error {
// must be restarted. On a clean exit it returns nil.
// FIXME: Also watch the source directory when using obj.Source !!!
func (obj *FileRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil // TODO: should this be an error?
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
var err error

View File

@@ -108,11 +108,6 @@ func (obj *HostnameRes) Validate() error {
// Watch is the primary listener for this resource and it outputs events.
func (obj *HostnameRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil // TODO: should this be an error?
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
// if we share the bus with others, we will get each others messages!!

View File

@@ -135,11 +135,6 @@ func (obj *MsgRes) journalPriority() journal.Priority {
// Watch is the primary listener for this resource and it outputs events.
func (obj *MsgRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
// notify engine that we're running

View File

@@ -59,11 +59,6 @@ func (obj *NoopRes) Validate() error {
// Watch is the primary listener for this resource and it outputs events.
func (obj *NoopRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil // TODO: should this be an error?
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
// notify engine that we're running

View File

@@ -95,11 +95,6 @@ func (obj *NspawnRes) Validate() error {
// Watch for state changes and sends a message to the bus if there is a change
func (obj *NspawnRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
// this resource depends on systemd ensure that it's running

View File

@@ -168,11 +168,6 @@ Loop:
// Watch is the primary listener for this resource and it outputs events.
func (obj *PasswordRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil // TODO: should this be an error?
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
var err error

View File

@@ -109,11 +109,6 @@ func (obj *PkgRes) Validate() error {
// TODO: https://github.com/hughsie/PackageKit/issues/109
// TODO: https://github.com/hughsie/PackageKit/issues/110
func (obj *PkgRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
bus := packagekit.NewBus()

View File

@@ -280,12 +280,12 @@ func (obj *BaseRes) AssociateData(data *Data) {
obj.debug = data.Debug
}
// IsWatching tells us if the Watch() function is running.
// IsWatching tells us if the Worker() function is running.
func (obj *BaseRes) IsWatching() bool {
return obj.watching
}
// SetWatching stores the status of if the Watch() function is running.
// SetWatching stores the status of if the Worker() function is running.
func (obj *BaseRes) SetWatching(b bool) {
obj.watching = b
}

View File

@@ -75,11 +75,6 @@ func (obj *SvcRes) Validate() error {
// Watch is the primary listener for this resource and it outputs events.
func (obj *SvcRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
// obj.Name: svc name

View File

@@ -74,11 +74,6 @@ func (obj *TimerRes) newTicker() *time.Ticker {
// Watch is the primary listener for this resource and it outputs events.
func (obj *TimerRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
// create a time.Ticker for the given interval

View File

@@ -132,11 +132,6 @@ func (obj *VirtRes) connect() (conn libvirt.VirConnection, err error) {
// Watch is the primary listener for this resource and it outputs events.
func (obj *VirtRes) Watch(processChan chan event.Event) error {
if obj.IsWatching() {
return nil
}
obj.SetWatching(true)
defer obj.SetWatching(false)
cuid := obj.Converger() // get the converger uid used to report status
conn, err := obj.connect()