code: func setConnected(c context.Context, id, hostname string, at time.Time) error {
  	// Check dscache in case vm.Connected is set now, to avoid a costly transaction.
  	vm := &model.VM{
  		ID: id,
  	}
  	switch err := datastore.Get(c, vm); {
  	case err != nil:
  		return errors.Annotate(err, "failed to fetch VM").Err()
  	case vm.Hostname != hostname:
  		return errors.Reason("bot %q does not exist", hostname).Err()
  	case vm.Connected > 0:
  		return nil
  	}
  	return datastore.RunInTransaction(c, func(c context.Context) error {
  		switch err := datastore.Get(c, vm); {
  		case err != nil:
  			return errors.Annotate(err, "failed to fetch VM").Err()
  		case vm.Hostname != hostname:
  			return errors.Reason("bot %q does not exist", hostname).Err()
  		case vm.Connected > 0:
  			return nil
  		}
  		vm.Connected = at.Unix()
  		if err := datastore.Put(c, vm); err != nil {
  			return errors.Annotate(err, "failed to store VM").Err()
  		}
  		return nil
  	}, nil)
  }
docs: // setConnected sets the Swarming bot as connected in the datastore if it isn't already.