code: func terminateBot(c context.Context, payload proto.Message) error {
  	task, ok := payload.(*tasks.TerminateBot)
  	switch {
  	case !ok:
  		return errors.Reason("unexpected payload %q", payload).Err()
  	case task.GetId() == "":
  		return errors.Reason("ID is required").Err()
  	case task.GetHostname() == "":
  		return errors.Reason("hostname 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.Hostname != task.Hostname:
  		// Instance is already destroyed and replaced. Don't terminate the new bot.
  		return errors.Reason("bot %q does not exist", task.Hostname).Err()
  	}
  	logging.Debugf(c, "terminating bot %q: %s", vm.Hostname, vm.Swarming)
  	srv := getSwarming(c, vm.Swarming)
  	_, err := srv.Bot.Terminate(vm.Hostname).Context(c).Do()
  	if err != nil {
  		if gerr, ok := err.(*googleapi.Error); ok {
  			if gerr.Code == http.StatusNotFound {
  				// Bot is already deleted.
  				logging.Debugf(c, "bot not found")
  				return nil
  			}
  			logErrors(c, gerr)
  			return errors.Reason("failed to terminate bot").Err()
  		}
  		return errors.Annotate(err, "failed to terminate bot").Err()
  	}
  	return nil
  }
docs: // terminateBot terminates an existing Swarming bot.