|
@@ -15,6 +15,10 @@ import (
|
|
|
|
|
|
var Auto = func() {
|
|
|
d := time.Now()
|
|
|
+ if config.Isjjr{
|
|
|
+ log.Println(d.Format("20060102"),"节假日")
|
|
|
+ return
|
|
|
+ }
|
|
|
nowday := time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
|
|
|
cluster.DescribeInstances() //查询多台实例的详细信息
|
|
|
ocrescs := mongodb.Find("ocr_ecs", bson.M{}, nil, bson.M{"AutoReleaseTime": 1}, false, -1, -1)
|
|
@@ -44,42 +48,49 @@ var Auto = func() {
|
|
|
log.Println("当前实例为空,无需释放", cluster.CID, )
|
|
|
return
|
|
|
}
|
|
|
- if ccnum == 0 && len(cluster.CID) > 0 {
|
|
|
- log.Println("释放所有实例", cluster.CID)
|
|
|
- for tmpIid, _ := range cluster.CID {
|
|
|
- ttt := mongodb.FindOne("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
- log.Println("5分钟后释放实例", tmpIid)
|
|
|
- go func(tmpIid string,ttt *map[string]interface{}) {
|
|
|
- time.Sleep(time.Minute * 5)
|
|
|
- config.Udpclient.WriteUdp([]byte("5分钟后释放实例"), mu.OP_DELETE_DOWNLOADERCODES, &net.UDPAddr{
|
|
|
- IP: net.ParseIP(util.ObjToString((*ttt)["ip_nw"])),
|
|
|
- Port: util.IntAll(config.Sysconfig["broadcast_port"]),
|
|
|
- })
|
|
|
- mongodb.Del("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
- cluster.DeleteInstance(tmpIid)
|
|
|
- log.Println("5分钟后释放实例完成", tmpIid)
|
|
|
- }(tmpIid,ttt)
|
|
|
- }
|
|
|
- } else {
|
|
|
- var tmpnum int
|
|
|
- for k, _ := range cluster.CID {
|
|
|
- if ccnum >= tmpnum {
|
|
|
- return
|
|
|
+ zsa := time.Date(d.Year(), d.Month(), d.Day(), util.IntAll(config.Sysconfig["swa"]), 0, 0, 0, d.Location())
|
|
|
+ zsb := time.Date(d.Year(), d.Month(), d.Day(), util.IntAll(config.Sysconfig["swb"]), 0, 0, 0, d.Location())
|
|
|
+
|
|
|
+ xwa := time.Date(d.Year(), d.Month(), d.Day(), util.IntAll(config.Sysconfig["xwa"]), 0, 0, 0, d.Location())
|
|
|
+ xwb := time.Date(d.Year(), d.Month(), d.Day(), util.IntAll(config.Sysconfig["xwb"]), 0, 0, 0, d.Location())
|
|
|
+ if (zsa.Before(d) && zsb.After(d)) || (xwa.Before(d) && xwb.After(d)){
|
|
|
+ if ccnum == 0 && len(cluster.CID) > 0 {
|
|
|
+ log.Println("释放所有实例", cluster.CID)
|
|
|
+ for tmpIid, _ := range cluster.CID {
|
|
|
+ ttt := mongodb.FindOne("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
+ log.Println("5分钟后释放实例", tmpIid)
|
|
|
+ go func(tmpIid string,ttt *map[string]interface{}) {
|
|
|
+ time.Sleep(time.Minute * 5)
|
|
|
+ config.Udpclient.WriteUdp([]byte("5分钟后释放实例"), mu.OP_DELETE_DOWNLOADERCODES, &net.UDPAddr{
|
|
|
+ IP: net.ParseIP(util.ObjToString((*ttt)["ip_nw"])),
|
|
|
+ Port: util.IntAll(config.Sysconfig["broadcast_port"]),
|
|
|
+ })
|
|
|
+ mongodb.Del("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
+ cluster.DeleteInstance(tmpIid)
|
|
|
+ log.Println("5分钟后释放实例完成", tmpIid)
|
|
|
+ }(tmpIid,ttt)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var tmpnum int
|
|
|
+ for k, _ := range cluster.CID {
|
|
|
+ if ccnum >= tmpnum {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tmpIid := k
|
|
|
+ ttt := mongodb.FindOne("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
+ log.Println("5分钟后释放实例", tmpIid)
|
|
|
+ go func(tmpIid string,ttt *map[string]interface{}) {
|
|
|
+ time.Sleep(time.Minute * 5)
|
|
|
+ config.Udpclient.WriteUdp([]byte("5分钟后释放实例"), mu.OP_DELETE_DOWNLOADERCODES, &net.UDPAddr{
|
|
|
+ IP: net.ParseIP(util.ObjToString((*ttt)["ip_nw"])),
|
|
|
+ Port: util.IntAll(config.Sysconfig["broadcast_port"]),
|
|
|
+ })
|
|
|
+ mongodb.Del("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
+ cluster.DeleteInstance(tmpIid)
|
|
|
+ log.Println("5分钟后释放实例完成", tmpIid)
|
|
|
+ }(tmpIid,ttt)
|
|
|
+ tmpnum--
|
|
|
}
|
|
|
- tmpIid := k
|
|
|
- ttt := mongodb.FindOne("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
- log.Println("5分钟后释放实例", tmpIid)
|
|
|
- go func(tmpIid string,ttt *map[string]interface{}) {
|
|
|
- time.Sleep(time.Minute * 5)
|
|
|
- config.Udpclient.WriteUdp([]byte("5分钟后释放实例"), mu.OP_DELETE_DOWNLOADERCODES, &net.UDPAddr{
|
|
|
- IP: net.ParseIP(util.ObjToString((*ttt)["ip_nw"])),
|
|
|
- Port: util.IntAll(config.Sysconfig["broadcast_port"]),
|
|
|
- })
|
|
|
- mongodb.Del("ocr_ecs", bson.M{"InstanceId": tmpIid})
|
|
|
- cluster.DeleteInstance(tmpIid)
|
|
|
- log.Println("5分钟后释放实例完成", tmpIid)
|
|
|
- }(tmpIid,ttt)
|
|
|
- tmpnum--
|
|
|
}
|
|
|
}
|
|
|
cluster.DescribeInstances()
|
|
@@ -216,12 +227,12 @@ func compute() int {
|
|
|
log.Println(496, sum, "<=", util.IntAll(config.Sysconfig["accumulated_task_lowlimit"]))
|
|
|
return 0
|
|
|
}
|
|
|
- mtmm := float64(overNum) / float64(nowtime-stime) / float64(len(cluster.CID)+3) //每台每秒
|
|
|
+ mtmm := float64(overNum) / float64(nowtime-stime) / float64(len(cluster.CID)+util.IntAll(config.Sysconfig["gdts"])) //每台每秒
|
|
|
if mtmm <= 0 {
|
|
|
- log.Println(501, overNum, int(nowtime-stime), (len(cluster.CID) + 3))
|
|
|
+ log.Println(501, overNum, int(nowtime-stime), (len(cluster.CID) + util.IntAll(config.Sysconfig["gdts"])))
|
|
|
return 0
|
|
|
}
|
|
|
- cc := float64(sum)/float64(util.IntAll(config.Sysconfig["corntime_consuming"]))/mtmm - float64(len(cluster.CID)) - 3
|
|
|
+ cc := float64(sum)/float64(util.IntAll(config.Sysconfig["corntime_consuming"]))/mtmm - float64(len(cluster.CID)) - float64(util.IntAll(config.Sysconfig["gdts"]))
|
|
|
log.Println("overNum:", overNum, ",hs:", int(nowtime-stime), ",mtms:", mtmm, ",sum:", sum, cc)
|
|
|
if cc > util.Float64All(config.Sysconfig["pernum"]) {
|
|
|
return util.IntAll(config.Sysconfig["pernum"])
|