Пример #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	configPath := flag.String("config", "", "Config path")
	flag.Parse()

	output := Util.Output{StartTime: time.Now()}
	output.Write("Starting...")

	// init
	var (
		err         error
		cacheClient Cache.Client
	)
	if cacheClient, _, _, err = Misc.Init(*configPath, false); err != nil {
		output.Write(fmt.Sprintf("Misc.Init() fail: %s", err.Error()))
		return
	}

	regionManager := Entity.NewRegionManager(cacheClient)
	var regions []Entity.Region
	if regions, err = regionManager.FindAll(); err != nil {
		output.Write(fmt.Sprintf("RegionManager.FindAll() fail: %s", err.Error()))
		return
	}

	characterCount := 0
	for _, region := range regions {
		realmManager := Entity.NewRealmManager(region, cacheClient)
		var realms []Entity.Realm
		if realms, err = realmManager.FindAll(); err != nil {
			output.Write(fmt.Sprintf("RealmManager.FindAll() fail: %s", err.Error()))
			return
		}

		for _, realm := range realms {
			characterManager := Character.NewManager(realm, cacheClient)
			var names []string
			if names, err = characterManager.GetNames(); err != nil {
				output.Write(fmt.Sprintf("CharacterManager.GetNames() fail: %s", err.Error()))
				return
			}
			characterCount += len(names)
		}
	}
	output.Write(fmt.Sprintf("Characters in the world: %d", characterCount))

	output.Conclude()
}
Пример #2
0
func process(inJob DownloadRealm.Job, cacheClient Cache.Client) (job Job) {
	// misc
	job = newJob(inJob)
	realm := inJob.Realm

	if inJob.Err != nil {
		job.Err = errors.New(fmt.Sprintf("DownloadRealm.Job() had an error (%s)", inJob.Err.Error()))
		return
	}

	if !inJob.CanContinue() {
		return
	}

	/*
		character handling
	*/
	characterManager := Character.NewManager(realm, cacheClient)

	// gathering existing characters
	var (
		existingNames []string
		err           error
	)
	if existingNames, err = characterManager.GetNames(); err != nil {
		job.Err = errors.New(fmt.Sprintf("CharacterManager.GetNames() failed (%s)", err.Error()))
		return
	}

	// gathering new characters
	if err = characterManager.PersistAll(inJob.GetNewCharacters(existingNames)); err != nil {
		job.Err = errors.New(fmt.Sprintf("CharacterManager.PersistAll() failed (%s)", err.Error()))
		return
	}

	/*
		item handling
	*/
	job.blizzItemIds = inJob.GetBlizzItemIds()

	return
}