Exemple #1
0
/*
	funcs
*/
func DoWork(in chan Entity.Realm, cacheClient Cache.Client) chan Job {
	out := make(chan Job)

	worker := func() {
		for realm := range in {
			out <- process(realm, cacheClient)
		}
	}
	postWork := func() { close(out) }
	Queue.Work(4, worker, postWork)

	return out
}
Exemple #2
0
/*
	funcs
*/
func DoWork(in chan DownloadRealm.Job, cacheClient Cache.Client) (chan Job, chan error) {
	out := make(chan Job)
	alternateOut := make(chan Job)
	alternateOutDone := make(chan error)

	worker := func() {
		for inJob := range in {
			job := process(inJob, cacheClient)
			out <- job
			alternateOut <- job
		}
	}
	postWork := func() {
		close(out)
		close(alternateOut)
	}
	Queue.Work(1, worker, postWork)

	// gathering up the list of unique items
	go func() {
		// waiting for the jobs to drain out
		jobs := Jobs{}
		for job := range alternateOut {
			if !job.CanContinue() {
				continue
			}

			jobs.list = append(jobs.list, job)
		}

		// gathering existing items
		var (
			existingBlizzIds []int64
			err              error
		)
		itemManager := Entity.ItemManager{Client: cacheClient}
		if existingBlizzIds, err = itemManager.GetBlizzIds(); err != nil {
			alternateOutDone <- err
		}
		if err = itemManager.PersistAll(jobs.getNewItems(existingBlizzIds)); err != nil {
			alternateOutDone <- err
		}

		alternateOutDone <- nil
	}()

	return out, alternateOutDone
}