You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: orchestrator.go
    path of file: ./repos/moby/vendor/github.com/moby/swarmkit/v2/manager/orchestrator/jobs
    
    the code of the file until where you have to start completion: package jobs

import (
	"context"
	"sync"

	"github.com/docker/go-events"

	"github.com/moby/swarmkit/v2/api"
	"github.com/moby/swarmkit/v2/log"
	"github.com/moby/swarmkit/v2/manager/orchestrator"
	"github.com/moby/swarmkit/v2/manager/orchestrator/jobs/global"
	"github.com/moby/swarmkit/v2/manager/orchestrator/jobs/replicated"
	"github.com/moby/swarmkit/v2/manager/orchestrator/restart"
	"github.com/moby/swarmkit/v2/manager/orchestrator/taskinit"
	"github.com/moby/swarmkit/v2/manager/state/store"
)

// Reconciler is the type that holds the reconciliation logic for the
// orchestrator. It exists so that the logic of actually reconciling and
// writing to the store is separated from the orchestrator, to make the event
// handling logic in the orchestrator easier to test.
type Reconciler interface {
	taskinit.InitHandler

	ReconcileService(id string) error
}

// Orchestrator is the combined orchestrator controlling both Global and
// Replicated Jobs. Initially, these job types were two separate orchestrators,
// like the Replicated and Global orchestrators. However, it became apparent
// that because of the simplicity of Jobs as compared to Services, one combined
// orchestrator suffices for both job types.
type Orchestrator struct {
	store *store.MemoryStore

	// two reconcilers, one for each service type

	replicatedReconciler Reconciler
	globalReconciler     Reconciler

	// startOnce is a function that stops the orchestrator from being started
	// multiple times.
	startOnce sync.Once

	// restartSup
    
func (o *Orchestrator) init(ctx context.Context) {
	var (
		services []*api.Service
	)

	// there are several components to the Orchestrator that are interfaces
	// designed to be swapped out in testing. in production, these fields will
	// all be unset, and be initialized here. in testing, we will set fakes,
	// and this initialization will be skipped.

	if o.restartSupervisor == nil {
		o.restartSupervisor = restart.NewSupervisor(o.store)
	}

	if o.replicatedReconciler == nil {
		// the cluster might be nil, but that doesn't matter.
		o.replicatedReconciler = replicated.NewReconciler(o.store, o.restartSupervisor)
	}

	if o.globalReconciler == nil {
		o.globalReconciler = global.NewReconciler(o.store, o.restartSupervisor)
	}

	if o.checkTasksFunc == nil {
		o.checkTasksFunc = taskinit.CheckTasks
	}

	o.watchChan, o.watchCancel, _ = store.ViewAndWatch(o.store, func(tx store.ReadTx) error {
		services, _ = store.FindServices(tx, store.All)
		return nil
	})

	// checkTasksFunc is used to resume any in-progress restarts that were
	// interrupted by a leadership change. In other orchestrators, this
	// additionally queues up some tasks to be restarted. However, the jobs
	// orchestrator will make a reconciliation pass across all services
	// immediately after this, and so does not need to restart any tasks; they
	// will be restarted during this pass.
	//
	// we cannot call o.checkTasksFunc inside of store.ViewAndWatch above.
	// despite taking a callback with a ReadTx, it actually performs an Update,
	// which acquires a lock and will result in a deadlock. instead, do
	// o.checkTasksFunc here.
	o.store.View(func(tx store.ReadTx) {
		o.checkTasksFunc(ctx, o.store, tx, o.replicatedReconciler, o.restartSupervisor)
		o.checkTasksFunc(ctx, o.store, tx, o.globalReconciler, o.restartSupervisor)
	})

	for _, service := range services {
		if orchestrator.IsReplicatedJob(service) {
			if err := o.replicatedReconciler.ReconcileService(service.ID); err != nil {
				log.G(ctx).WithField(
					"service.id", service.ID,
				).WithError(err).Error("error reconciling replicated job")
			}
		}

		if orchestrator.IsGlobalJob(service) {
			if err := o.globalReconciler.ReconcileService(service.ID); err != nil {
				log.G(ctx).WithField(
					"service.id", service.ID,
				).WithError(err).Error("error reconciling global job")
			}
		}
	}
}