resources: Force a sane default for zero value limiting
The default UnmarshalYAML on *BaseRes doesn't work properly at the moment, so hack in a default so that we don't need to specify one if the MetaParams struct isn't specified. The problem is that if there isn't a meta value added, its UnmarshalYAML doesn't get a chance to run.
This commit is contained in:
@@ -206,6 +206,29 @@ type BaseRes struct {
|
|||||||
//refreshState StatefulBool // TODO: future stateful bool
|
//refreshState StatefulBool // TODO: future stateful bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML is the custom unmarshal handler for the BaseRes struct. It is
|
||||||
|
// primarily useful for setting the defaults, in particular if meta is absent!
|
||||||
|
// FIXME: uncommenting this seems to block the graph from exiting, how come???
|
||||||
|
//func (obj *BaseRes) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
// DefaultBaseRes := BaseRes{
|
||||||
|
// // without specifying a default here, if we don't specify *any*
|
||||||
|
// // meta parameters in the yaml file, then the UnmarshalYAML for
|
||||||
|
// // the MetaParams struct won't run, and we won't get defaults!
|
||||||
|
// MetaParams: DefaultMetaParams, // force a default
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type rawBaseRes BaseRes // indirection to avoid infinite recursion
|
||||||
|
// raw := rawBaseRes(DefaultBaseRes) // convert; the defaults go here
|
||||||
|
// //raw := rawBaseRes{}
|
||||||
|
|
||||||
|
// if err := unmarshal(&raw); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// *obj = BaseRes(raw) // restore from indirection with type conversion!
|
||||||
|
// return nil
|
||||||
|
//}
|
||||||
|
|
||||||
// UIDExistsInUIDs wraps the IFF method when used with a list of UID's.
|
// UIDExistsInUIDs wraps the IFF method when used with a list of UID's.
|
||||||
func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool {
|
func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool {
|
||||||
for _, u := range uids {
|
for _, u := range uids {
|
||||||
@@ -263,6 +286,12 @@ func (obj *BaseRes) Init() error {
|
|||||||
obj.mutex = &sync.Mutex{}
|
obj.mutex = &sync.Mutex{}
|
||||||
obj.events = make(chan *event.Event) // unbuffered chan to avoid stale events
|
obj.events = make(chan *event.Event) // unbuffered chan to avoid stale events
|
||||||
obj.started = make(chan struct{}) // closes when started
|
obj.started = make(chan struct{}) // closes when started
|
||||||
|
|
||||||
|
// FIXME: force a sane default until UnmarshalYAML on *BaseRes works...
|
||||||
|
if obj.Meta().Burst == 0 && obj.Meta().Limit == 0 { // blocked
|
||||||
|
obj.Meta().Limit = rate.Inf
|
||||||
|
}
|
||||||
|
|
||||||
//dir, err := obj.VarDir("")
|
//dir, err := obj.VarDir("")
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return errwrap.Wrapf(err, "VarDir failed in Init()")
|
// return errwrap.Wrapf(err, "VarDir failed in Init()")
|
||||||
|
|||||||
Reference in New Issue
Block a user