code: func (ctl *Controller) AbortJob(c context.Context, id JobID) (job *Job, err error) {
  	err = runTxn(c, func(c context.Context) error {
  		var err error
  		switch job, err = getJob(c, id); {
  		case err != nil:
  			return err
  		case isFinalState(job.State) || job.State == State_ABORTING:
  			return nil // nothing to abort, already done
  		case job.State == State_STARTING:
  			// Shards haven't been launched yet. Kill the job right away.
  			job.State = State_ABORTED
  		case job.State == State_RUNNING:
  			// Running shards will discover that the job is aborting and will
  			// eventually move into ABORTED state (notifying the job about it). Once
  			// all shards report they are done, the job itself will switch into
  			// ABORTED state.
  			job.State = State_ABORTING
  		}
  		job.Updated = clock.Now(c).UTC()
  		return errors.Annotate(datastore.Put(c, job), "failed to store Job entity").Tag(transient.Tag).Err()
  	})
  	if err != nil {
  		job = nil // don't return bogus data in case txn failed to land
  	}
  	return
  }
docs: // AbortJob aborts a job and returns its most recent state.
  //
  // Silently does nothing if the job is finished or already aborted.
  //
  // Returns ErrNoSuchJob is there's no such job at all. All other possible errors
  // are transient and they are marked as such.