Exemplo n.º 1
0
// add submission
func (this *Submissions) Add(pid int, uid int, ptype string, language string, code string, judgerName string) (int64, error) {

	o := orm.NewOrm()
	var subm Submissions
	subm.Pid = pid
	subm.Uid = uid

	if len(ptype) == 0 {
		ptype = "assert"
	}
	subm.Type = ptype
	subm.Language = language
	subm.Code = code
	subm.Judger = judgerName
	subm.Status = "TA"
	subm.SubmitTime = time.Now()
	subm.JudgeTime = time.Now()

	id, err := o.Insert(&subm)

	if err != nil {
		return id, err
	}

	jdg := judger.Get("default")
	jdg.AddTask(id, language, code)

	return id, err
}
Exemplo n.º 2
0
func CheckJudger() error {
	jdg := judger.Get("default")
	err := jdg.Ping()
	if err != nil {
		log.Warnln("reconnecting")
		reconnect()
	}

	return nil
}
Exemplo n.º 3
0
func (this *Submissions) GetSubmissionStatus(id int) (string, error) {

	jdg := judger.Get("default")
	response, err := jdg.GetStatus(int64(id))

	if err != nil {
		log.Warnln("send Request failed:", err)
	}

	info := response["info"].(map[string]interface{})

	o := orm.NewOrm()
	var subm Submissions
	subm.Id = id
	err = o.Read(&subm, "Id")

	if err != nil {
		log.Warnf("记录[%d]不存在\n", id)
		return "", err
	} else {

		status := info["run_result"].(string)

		if status == "PEN" {
			subm.Status = "AC"
		} else if status == "PRE" {
			subm.Status = "RE"
		} else if status == "POM" {
			subm.Status = "MLE"
		} else if status == "POT" {
			subm.Status = "TLE"
		} else if status == "POL" {
			subm.Status = "OLE"
		} else if status == "PSF" {
			subm.Status = "PSF"
		} else if status == "EC" {
			subm.Status = "CE"
		} else {
			subm.Status = "UK"
		}

		subm.BuildLog = info["build_log"].(string)
		exe_debug, ok := info["executer_debug"].(string)
		if ok {
			subm.ExecuterDebug = exe_debug
		}
		o.Update(&subm)

		return subm.Status, err
	}
}
Exemplo n.º 4
0
func reconnect() {
	host := beego.AppConfig.String("judgerhost")
	port, err := beego.AppConfig.Int("judgerport")
	pass := beego.AppConfig.String("judgerpass")

	if err != nil {
		port = 1004
	}

	jdg := judger.Get("default")
	err = jdg.Start(host, port, pass)

	if err != nil {
		log.Warnln("Reconnect Failed", err)
	} else {
		log.Blueln("Reconnected.")
	}

}