code: func (b *server) LeaseArchiveTasks(c context.Context, req *logdog.LeaseRequest) (*logdog.LeaseResponse, error) {
  	duration, err := ptypes.Duration(req.LeaseTime)
  	if err != nil {
  		return nil, err
  	}
  
  	logging.Infof(c, "got request to lease %d tasks for %s", req.MaxTasks, req.GetLeaseTime())
  	tasks, err := taskqueue.Lease(c, int(req.MaxTasks), ArchiveQueueName, duration)
  	if err != nil {
  		logging.WithError(err).Errorf(c, "could not lease %d tasks from queue", req.MaxTasks)
  		return nil, err
  	}
  	archiveTasks := make([]*logdog.ArchiveTask, 0, len(tasks))
  	for _, task := range tasks {
  		at, err := archiveTask(task)
  		if err != nil {
  			// Ignore malformed name errors, just log them.
  			logging.WithError(err).Errorf(c, "while leasing task")
  			continue
  		}
  		// Optimization: Delete the task if it's already archived.
  		if isArchived(c, at) {
  			if err := taskqueue.Delete(c, ArchiveQueueName, task); err != nil {
  				logging.WithError(err).Errorf(c, "failed to delete %s/%s (%s)", at.Project, at.Id, task.Name)
  			}
  			continue
  		}
  		archiveTasks = append(archiveTasks, at)
  		leaseTask.Add(c, 1, task.RetryCount)
  	}
  	logging.Infof(c, "Leasing %d tasks", len(archiveTasks))
  	return &logdog.LeaseResponse{Tasks: archiveTasks}, nil
  }
docs: // LeaseArchiveTasks leases archive tasks to the requestor from a pull queue.