func (ttles *TTLExpirationScheduler) AddManifest(manifestRef reference.Canonical, ttl time.Duration) error {
	ttles.Lock()
	defer ttles.Unlock()
	if ttles.stopped {
		return fmt.Errorf("scheduler not started")
	}
	ttles.add(manifestRef, ttl, entryTypeManifest)
	return nil
}
AddManifest schedules a manifest cleanup after ttl expires
package scheduler
import (
	"encoding/json"
	"fmt"
	"sync"
	"time"
	"github.com/docker/distribution/context"
	"github.com/docker/distribution/reference"
	"github.com/docker/distribution/registry/storage/driver"
)
type expiryFunc func(reference.Reference) error
const (
	entryTypeBlob = iota
	entryTypeManifest
	indexSaveFrequency = 5 * time.Second
)
type schedulerEntry struct {
	Key       string    `json:"Key"`
	Expiry    time.Time `json:"ExpiryData"`
	EntryType int       `json:"EntryType"`
	timer *time.Timer
}
func New(ctx context.Context, driver driver.StorageDriver, path string) *TTLExpirationScheduler {
	return &TTLExpirationScheduler{
		entries:         make(map[string]*schedulerEntry),
		driver:          driver,
		pathToStateFile: path,
		ctx:             ctx,
		stopped:         true,
		doneChan:        make(chan struct{}),
		saveTimer:       time.NewTicker(indexSaveFrequency),
	}
}
type TTLExpirationScheduler struct {
	sync.Mutex
	entries map[string]*schedulerEntry
	driver          driver.StorageDriver
	ctx             context.Context
	pathToStateFile string
	stopped bool
	onBlobExpire     expiryFunc
	onManifestExpire expiryFunc
	indexDirty bool
	saveTimer  *time.Ticker
	doneChan   chan struct{}
}
func (ttles *TTLExpirationScheduler) OnBlobExpire(f expiryFunc) {
	ttles.Lock()
	defer ttles.Unlock()
	ttles.onBlobExpire = f
}
func (ttles *TTLExpirationScheduler) OnManifestExpire(f expiryFunc) {
	ttles.Lock()
	defer ttles.Unlock()
	ttles.onManifestExpire = f
}
func (ttles *TTLExpirationScheduler) AddBlob(blobRef reference.Canonical, ttl time.Duration) error {
	ttles.Lock()
	defer ttles.Unlock()
	if ttles.stopped {
		return fmt.Errorf("scheduler not started")
	}
	ttles.add(blobRef, ttl, entryTypeBlob)
	return nil
}