Example #1
0
func (c *Container) UpdateNeed() bool {
	consumption := c.consumption
	c.consumption = 0
	if consumption < config.GetConfig().Threshold {
		return false
	}
	return true
}
Example #2
0
func Start() {
	c := config.GetConfig()
	captchas := captchaGenerate(c.InitialCount)
	CaptchaContainer.Append(captchas...)
	log.Print("init success.")
	ticker := time.NewTicker(time.Second * time.Duration(c.CheckInterval))
	go func() {
		for _ = range ticker.C {
			go workder()
		}
	}()
}
Example #3
0
func workder() {
	if !CaptchaContainer.UpdateNeed() {
		return
	}
	captchas := captchaGenerate(config.GetConfig().UpdateCount)
	CaptchaContainer.Lock()
	oldCaptchas := CaptchaContainer.Update(captchas...)
	CaptchaContainer.Unlock()
	for _, captcha := range oldCaptchas {
		fileName := strings.Split(captcha, "|")[0]
		os.Remove("../tmp/" + fileName)
	}
	log.Print("update suceess.")
}