From ed2dfe0809462fbfa16a89723c8f19e47748c306 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sat, 22 Dec 2018 04:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9D=A1=E4=BB=B6=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E7=9A=84=E8=A1=A8=E8=BE=BE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crontab_test.go | 2 +- interval_base.go | 103 ++++++++++++++++++++++++++--------------------- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/crontab_test.go b/crontab_test.go index 8a32427..fcb7225 100644 --- a/crontab_test.go +++ b/crontab_test.go @@ -79,7 +79,7 @@ func TestParseIntervalPlus(t *testing.T) { log.SetFlags(log.Llongfile) - crontab := "f2|f2>3|f3>4|1|s4>5" + crontab := "f=2|f2>=3|f3>=4|1|s4>=5" cron := NewCrontab(crontab) i := 0 diff --git a/interval_base.go b/interval_base.go index 3512525..c3812bd 100644 --- a/interval_base.go +++ b/interval_base.go @@ -1,6 +1,7 @@ package crontab import ( + "errors" "strconv" "strings" @@ -38,6 +39,58 @@ func (rlr *NodeCount) Compare(v plist.INode) bool { return rlr.GetValue().(int) > v.GetValue().(int) } +func parseIntervalFail(interval *hInterval, FN string) { + scharIndex := strings.Index(FN, ">") + if scharIndex != -1 { + + if FN[scharIndex+1] != '=' { + panic(errors.New("= is not exist")) + } + + fc := FN[0:scharIndex] + flr := FN[scharIndex+2:] + + node := new(NodeCount) + node.SetValue(getInt(fc[1:])) + node.randLR = parseRandLR(flr) + interval.PlanFailCount.Insert(node) + } else { + + if FN[1] != '=' { + panic(errors.New("= is not exist")) + } + + fvalue := FN[2:] + interval.PlanFail = append(interval.PlanFail, parseRandLR(fvalue)) + } +} + +func parseIntervalSuccess(interval *hInterval, FN string) { + scharIndex := strings.Index(FN, ">") + if scharIndex != -1 { + if FN[scharIndex+1] != '=' { + panic(errors.New("= is not exist")) + } + + tc := FN[0:scharIndex] + tlr := FN[scharIndex+2:] + + node := new(NodeCount) + node.SetValue(getInt(tc[1:])) + node.randLR = parseRandLR(tlr) + interval.PlanTrueCount.Insert(node) + + } else { + + if FN[1] != '=' { + panic(errors.New("= is not exist")) + } + + tvalue := FN[2:] + interval.PlanTrue = append(interval.PlanTrue, parseRandLR(tvalue)) + } +} + func parseIntervalString(crontab string) []interface{} { var result []interface{} @@ -73,54 +126,12 @@ func parseIntervalString(crontab string) []interface{} { switch FN[0] { case 'f', 'F': - scharIndex := strings.Index(FN, ">") - if scharIndex != -1 { - - fc := FN[0:scharIndex] - flr := FN[scharIndex+1:] - - node := new(NodeCount) - node.SetValue(getInt(fc[1:])) - node.randLR = parseRandLR(flr) - interval.PlanFailCount.Insert(node) - - } else { - fvalue := FN[1:] - interval.PlanFail = append(interval.PlanFail, parseRandLR(fvalue)) - } - + parseIntervalFail(interval, FN) case 's', 'S': - scharIndex := strings.Index(FN, ">") - if scharIndex != -1 { - tc := FN[0:scharIndex] - tlr := FN[scharIndex+1:] - - node := new(NodeCount) - node.SetValue(getInt(tc[1:])) - node.randLR = parseRandLR(tlr) - interval.PlanTrueCount.Insert(node) - - } else { - tvalue := FN[1:] - interval.PlanTrue = append(interval.PlanTrue, parseRandLR(tvalue)) - } - + parseIntervalSuccess(interval, FN) default: - FN = "s" + FN - scharIndex := strings.Index(FN, ">") - if scharIndex != -1 { - tc := FN[0:scharIndex] - tlr := FN[scharIndex+1:] - - node := new(NodeCount) - node.SetValue(getInt(tc[1:])) - node.randLR = parseRandLR(tlr) - interval.PlanTrueCount.Insert(node) - - } else { - tvalue := FN[1:] - interval.PlanTrue = append(interval.PlanTrue, parseRandLR(tvalue)) - } + FN = "s=" + FN + parseIntervalSuccess(interval, FN) } }