code: func getActiveShard(c context.Context, shardID, taskNum int64) (*shard, error) {
  	sh := &shard{ID: shardID}
  	switch err := datastore.Get(c, sh); {
  	case err == datastore.ErrNoSuchEntity:
  		return nil, errors.Annotate(err, "no such shard, aborting").Err() // fatal, no retries
  	case err != nil:
  		return nil, errors.Annotate(err, "failed to fetch the shard").Tag(transient.Tag).Err()
  	case isFinalState(sh.State):
  		logging.Warningf(c, "The shard is finished already")
  		return nil, nil
  	case sh.ProcessTaskNum != taskNum:
  		logging.Warningf(c, "The task is stale (shard's task_num is %d, but task's is %d). Skipping it", sh.ProcessTaskNum, taskNum)
  		return nil, nil
  	default:
  		return sh, nil
  	}
  }
docs: // getActiveShard returns shard entity with given ID if its still in active
  // state and its ProcessTaskNum matches the given taskNum.
  //
  // Returns:
  //   (*shard, nil) if the shard is there and matches the criteria.
  //   (nil, nil) if the shard is there, but it doesn't match the criteria.
  //   (nil, transient error) on datastore fetch errors.
  //   (nil, fatal error) if there's no such shard at all.