예제 #1
0
func prepareChannel(options ReplaceOptions) (rawEvents, throttledEvents chan themekit.AssetEvent) {
	rawEvents = make(chan themekit.AssetEvent)
	if options.Bucket == nil {
		return rawEvents, rawEvents
	}

	foreman := themekit.NewForeman(options.Bucket)
	foreman.JobQueue = rawEvents
	foreman.WorkerQueue = make(chan themekit.AssetEvent)
	foreman.IssueWork()
	return foreman.JobQueue, foreman.WorkerQueue
}
예제 #2
0
func watchForChangesAndIssueWork(options WatchOptions, eventLog chan themekit.ThemeEvent) {
	client := options.Client
	config := client.GetConfiguration()
	bucket := client.LeakyBucket()
	bucket.TopUp()

	foreman := themekit.NewForeman(bucket)
	foreman.OnIdle = func() {
		if len(options.NotifyFile) > 0 {
			os.Create(options.NotifyFile)
			os.Chtimes(options.NotifyFile, time.Now(), time.Now())
		}
	}
	watcher := constructFileWatcher(options.Directory, config)
	foreman.JobQueue = watcher
	foreman.IssueWork()

	for i := 0; i < config.Concurrency; i++ {
		workerName := fmt.Sprintf("%s Worker #%d", config.Domain, i)
		go spawnWorker(workerName, foreman.WorkerQueue, client, eventLog)
	}
}