code: func manageBot(c context.Context, payload proto.Message) error {
  	task, ok := payload.(*tasks.ManageBot)
  	switch {
  	case !ok:
  		return errors.Reason("unexpected payload %q", payload).Err()
  	case task.GetId() == "":
  		return errors.Reason("ID is required").Err()
  	}
  	vm := &model.VM{
  		ID: task.Id,
  	}
  	switch err := datastore.Get(c, vm); {
  	case err == datastore.ErrNoSuchEntity:
  		return nil
  	case err != nil:
  		return errors.Annotate(err, "failed to fetch VM").Err()
  	case vm.URL == "":
  		logging.Debugf(c, "instance %q does not exist", vm.Hostname)
  		return nil
  	}
  	logging.Debugf(c, "fetching bot %q: %s", vm.Hostname, vm.Swarming)
  	bot, err := getSwarming(c, vm.Swarming).Bot.Get(vm.Hostname).Context(c).Do()
  	if err != nil {
  		if gerr, ok := err.(*googleapi.Error); ok {
  			if gerr.Code == http.StatusNotFound {
  				logging.Debugf(c, "bot not found")
  				return manageMissingBot(c, vm)
  			}
  			logErrors(c, gerr)
  			return errors.Reason("failed to fetch bot").Err()
  		}
  		return errors.Annotate(err, "failed to fetch bot").Err()
  	}
  	logging.Debugf(c, "found bot")
  	return manageExistingBot(c, bot, vm)
  }
docs: // manageBot manages a Swarming bot.