group_power_exp.go 1.09 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4
package group_cron

import (
	"git.hilo.cn/hilo-common/domain"
hujiebin's avatar
hujiebin committed
5
	"git.hilo.cn/hilo-common/resource/config"
hujiebin's avatar
hujiebin committed
6
	"github.com/robfig/cron"
hujiebin's avatar
hujiebin committed
7
	"hilo-group/domain/event/group_power_ev"
hujiebin's avatar
hujiebin committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	"hilo-group/domain/model/groupPower_m"
)

// 清理家族经验和等级
func GroupPowerExpClear() {
	c := cron.New()
	// 每月1号0:00经验值清零
	spec := "0 0 0 1 * ?"
	_ = c.AddFunc(spec, func() {
		var model = domain.CreateModelNil()
		if err := groupPower_m.ClearGroupPowerExp(model); err != nil {
			model.Log.Errorf("ClearGroupPowerExp fail:%v", err)
		}
	})

	// 每分钟清理过期家族等级
	spec = "0 * * * * ?"
	_ = c.AddFunc(spec, func() {
		var model = domain.CreateModelNil()
		if err := groupPower_m.ClearGroupPowerGrade(model); err != nil {
			model.Log.Errorf("ClearGroupPowerGrade fail:%v", err)
		}
	})
hujiebin's avatar
hujiebin committed
31 32
	// 每月20号发家族即将过期通知
	spec = "0 0 0 20 * ?"
hujiebin's avatar
hujiebin committed
33 34 35
	if !config.AppIsRelease() {
		spec = "0 */10 * * * ?"
	}
hujiebin's avatar
hujiebin committed
36 37 38 39
	_ = c.AddFunc(spec, func() {
		var model = domain.CreateModelNil()
		_ = group_power_ev.PublishGroupPowerExpireNotice(model, &group_power_ev.GroupPowerExpireNoticeEvent{})
	})
hujiebin's avatar
hujiebin committed
40 41
	c.Start()
}