Ejemplo n.º 1
0
func reloadJobFromDB(cr *cron.Cron, error_jobs map[string]error, backend *dbBackend, arguments map[string]interface{}, id int64, name string) {
	message_prefix := "[sys] reload job -"
	if "" == name {
		message_prefix = "[sys] load new job -"
	}

	job, e := backend.find(id)
	if nil != e {
		if "" == name {
			log.Println(message_prefix, "[", id, "]")
		} else {
			log.Println(message_prefix, name)
		}
		return
	}
	e = afterLoad(job, arguments)
	if nil != e {
		log.Println(message_prefix, job.name)
		return
	}

	id_str := fmt.Sprint(id)
	log.Println(message_prefix, job.name)
	cr.Unschedule(id_str)
	delete(error_jobs, id_str)

	sch, e := Parse(job.expression)
	if nil != e {
		msg := errors.New("[" + job.name + "] schedule failed," + e.Error())
		error_jobs[id_str] = msg
		log.Println(msg)
		return
	}
	cr.Schedule(id_str, sch, job)
}
Ejemplo n.º 2
0
func Schedule(c *cron.Cron, id string, schedule cron.Schedule, cmd cron.Job) {
	c.Schedule(id, schedule, cmd)
}