// processNextWorkItem will read a single work item off the work queue and
// attempt to process it, by calling the syncHandler.
processNextWorkItem will read a single work item off the work queue and
attempt to process it, by calling the syncHandler.
// processNextWorkItem will read a single work item off the work queue and // attempt to process it by calling the syncHandler .
func (c *MPIJobController) processNextWorkItem() bool {
	obj, shutdown := c.queue.Get()
	if shutdown {
		return false
	}
	err := func(obj interface{}) error {
		defer c.queue.Done(obj)
		var key string
		var ok bool
		if key, ok = obj.(string); !ok {
			c.queue.Forget(obj)
			runtime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj))
			return nil
		}
		if err := c.syncHandler(key); err != nil {
			return fmt.Errorf("error syncing '%s': %s", key, err.Error())
		}
		c.queue.Forget(obj)
		glog.Infof("Successfully synced '%s'", key)
		return nil
	}(obj)
	if err != nil {
		runtime.HandleError(err)
		return true
	}
	return true
}
func ( c * MPIJobController ) processNextWorkItem ( ) bool { obj , shutdown := c . queue . Get ( ) if shutdown { return false } err := func ( obj interface { } ) error { defer c . queue . Done ( obj ) var key string var ok bool if key , ok = obj . ( string ) ; ! ok { c . queue . Forget ( obj ) runtime . HandleError ( fmt . Errorf ( " " , obj ) ) return nil } if err := c . syncHandler ( key ) ; err != nil { return fmt . Errorf ( " " , key , err . Error ( ) ) } c . queue . Forget ( obj ) glog . Infof ( " " , key ) return nil } ( obj ) if err != nil { runtime . HandleError ( err ) return true } return true }
processNextWorkItem will read a single work item off the work queue and
attempt to process it, by calling the syncHandler.
processNextWorkItem will read a single work item off the work queue and attempt to process it by calling the syncHandler .
// We wrap this block in a func so we can defer c.queue.Done. // We call Done here so the work queue knows we have finished // processing this item. We also must remember to call Forget if we // do not want this work item being re-queued. For example, we do // not call Forget if a transient error occurs, instead the item is // put back on the work queue and attempted again after a back-off // period. // We expect strings to come off the work queue. These are of the // form namespace/name. We do this as the delayed nature of the // work queue means the items in the informer cache may actually be // more up to date that when the item was initially put onto the // work queue. // As the item in the work queue is actually invalid, we call // Forget here else we'd go into a loop of attempting to // process a work item that is invalid. // Run the syncHandler, passing it the namespace/name string of the // MPIJob resource to be synced. // Finally, if no error occurs we Forget this item so it does not // get queued again until another change happens.