2015-10-29 21:47:39 +00:00
|
|
|
package watch
|
|
|
|
|
|
|
|
// The watch package provides a means of describing a watch for a blocking
|
|
|
|
// query. It is exported so it may be shared between Nomad's RPC layer and
|
|
|
|
// the underlying state store.
|
|
|
|
|
|
|
|
// Item describes the scope of a watch. It is used to provide a uniform
|
2015-11-04 19:18:17 +00:00
|
|
|
// input for subscribe/unsubscribe and notification firing. Specifying
|
|
|
|
// multiple fields does not place a watch on multiple items. Each Item
|
|
|
|
// describes exactly one scoped watch.
|
2015-10-29 21:47:39 +00:00
|
|
|
type Item struct {
|
|
|
|
Alloc string
|
2015-10-29 23:20:57 +00:00
|
|
|
AllocEval string
|
2015-10-29 22:26:14 +00:00
|
|
|
AllocJob string
|
2015-10-29 21:47:39 +00:00
|
|
|
AllocNode string
|
|
|
|
Eval string
|
|
|
|
Job string
|
|
|
|
Node string
|
|
|
|
Table string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Items is a helper used to construct a set of watchItems. It deduplicates
|
|
|
|
// the items as they are added using map keys.
|
|
|
|
type Items map[Item]struct{}
|
|
|
|
|
2015-10-30 15:42:23 +00:00
|
|
|
// NewItems creates a new Items set and adds the given items.
|
2015-10-29 21:47:39 +00:00
|
|
|
func NewItems(items ...Item) Items {
|
|
|
|
wi := make(Items)
|
|
|
|
for _, item := range items {
|
|
|
|
wi.Add(item)
|
|
|
|
}
|
|
|
|
return wi
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add adds an item to the watch set.
|
|
|
|
func (wi Items) Add(i Item) {
|
|
|
|
wi[i] = struct{}{}
|
|
|
|
}
|