code: func (r *Orchestrator) Run(ctx context.Context) error {
  	defer close(r.doneChan)
  
  	// Watch changes to services and tasks
  	queue := r.store.WatchQueue()
  	watcher, cancel := queue.Watch()
  	defer cancel()
  
  	// Balance existing services and drain initial tasks attached to invalid
  	// nodes
  	var err error
  	r.store.View(func(readTx store.ReadTx) {
  		if err = r.initTasks(ctx, readTx); err != nil {
  			return
  		}
  
  		if err = r.initServices(readTx); err != nil {
  			return
  		}
  
  		if err = r.initCluster(readTx); err != nil {
  			return
  		}
  	})
  	if err != nil {
  		return err
  	}
  
  	r.tick(ctx)
  
  	for {
  		select {
  		case event := <-watcher:
  			// TODO(stevvooe): Use ctx to limit running time of operation.
  			r.handleTaskEvent(ctx, event)
  			r.handleServiceEvent(ctx, event)
  			switch v := event.(type) {
  			case state.EventCommit:
  				r.tick(ctx)
  			case api.EventUpdateCluster:
  				r.cluster = v.Cluster
  			}
  		case <-r.stopChan:
  			return nil
  		}
  	}
  }
docs: // Run contains the orchestrator event loop. It runs until Stop is called.