示例#1
0
文件: variable.go 项目: unikk/cuto
func (v *variable) expandJob() (string, error) {
	if v.Place == plcServant {
		return ``, fmt.Errorf("Cannot use job variable in servant.")
	}
	j, ok := jobValues[v.Name]
	if !ok {
		return ``, fmt.Errorf("Job[%s] is not executed yet.", v.Name)
	}

	switch v.Tag {
	case `ID`:
		return j.ID, nil
	case `RC`:
		return j.RC, nil
	case `SD`:
		t, err := utctime.Parse(utctime.Default, j.SD)
		if err != nil {
			return ``, fmt.Errorf("Cannot parse time string[%s].", j.SD)
		}
		return t.Format("$ST" + utctime.NoDelimiter + "$"), nil
	case `ED`:
		t, err := utctime.Parse(utctime.Default, j.ED)
		if err != nil {
			return ``, fmt.Errorf("Cannot parse time string[%s].", j.ED)
		}
		return t.Format("$ST" + utctime.NoDelimiter + "$"), nil
	case `OUT`:
		return j.OUT, nil
	}

	return ``, fmt.Errorf("Undefined variable[%s].", v)
}
示例#2
0
文件: show.go 项目: unikk/cuto
func correctTimezone(utcStr string, isOutputUTC bool) string {
	if isOutputUTC {
		return utcStr
	}
	t, err := utctime.Parse(utctime.Default, utcStr)
	if err != nil {
		return utcStr
	}
	return t.FormatLocaltime(utctime.Default)
}
示例#3
0
文件: variable.go 项目: unikk/cuto
func (v *variable) expandTime() (string, error) {
	if v.Place == plcMaster {
		return ``, fmt.Errorf("Cannot use time variable in master.")
	}

	t, err := utctime.Parse(utctime.NoDelimiter, v.Name)
	if err != nil {
		return ``, fmt.Errorf("Cannot parse time variable[%s]. Reason[%s]", v.Name, err)
	}

	return t.FormatLocaltime(utctime.Default), nil
}
示例#4
0
func TestSearchLatestJoblog(t *testing.T) {
	conf := getJobCheckTestConfig()
	et, _ := utctime.Parse(utctime.Default, "2015-08-01 03:34:56.789")
	path, err := searchLatestJoblog(conf.Dir.JoblogDir, 1, "job1", et)
	if err != nil {
		t.Fatalf("Unexpected error occured: %s", err)
	}

	if !strings.HasSuffix(path, "1.testjob.job1.20150801120525.123.log") {
		t.Error("Unexpected path was got:")
		t.Log(path)
	}
}