本文整理匯總了Golang中github.com/rprp/hivego/schedule.ScheduleManager類的典型用法代碼示例。如果您正苦於以下問題:Golang ScheduleManager類的具體用法?Golang ScheduleManager怎麽用?Golang ScheduleManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ScheduleManager類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UpdateTask
//updateTask獲取客戶端發送的Task信息,並調用Job的UpdateTask方法將其
//持久化並更新至Job中。
//成功返回更新後的Task信息
func UpdateTask(params martini.Params, r render.Render, Ss *schedule.ScheduleManager, task schedule.Task) { // {{{
var err error
sid, sidok := params["sid"]
ssid, _ := strconv.Atoi(sid)
if !sidok || task.Name == "" || task.JobId == 0 {
e := fmt.Sprintf("[UpdateTask] task name is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if s := Ss.GetScheduleById(int64(ssid)); s != nil {
j, err := s.GetJobById(task.JobId)
if err != nil {
e := fmt.Sprintf("[UpdateTask] get job error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
}
err = j.UpdateTask(&task)
}
if err == nil {
r.JSON(200, task)
} else {
e := fmt.Sprintf("[UpdateTask] update task error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
}
} // }}}
示例2: DeleteRelTask
func DeleteRelTask(params martini.Params, ctx *web.Context, r render.Render, Ss *schedule.ScheduleManager) { // {{{
sid, _ := strconv.Atoi(params["sid"])
jid, _ := strconv.Atoi(params["jid"])
id, _ := strconv.Atoi(params["id"])
relid, _ := strconv.Atoi(params["relid"])
if sid == 0 || jid == 0 || id == 0 || relid == 0 {
e := fmt.Sprintf("[DeleteRelTask] [sid jid id relid] is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if s := Ss.GetScheduleById(int64(sid)); s != nil {
t := s.GetTaskById(int64(id))
if t == nil {
e := fmt.Sprintf("[DeleteRelTask] task is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
err := t.DeleteRelTask(int64(relid))
if err != nil {
e := fmt.Sprintf("[DeleteRelTask] delete task is error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
}
r.JSON(200, t)
}
} // }}}
示例3: AddTask
//addTask獲取客戶端發送的Task信息,調用Task的AddTask方法持久化。
//成功後根據其中的JobId找到對應Job將其添加
//成功返回添加好的Job信息
//錯誤返回err信息
func AddTask(params martini.Params, r render.Render, Ss *schedule.ScheduleManager, task schedule.Task) { // {{{
sid, sidok := params["sid"]
ssid, _ := strconv.Atoi(sid)
if !sidok || task.Name == "" || task.JobId == 0 {
e := fmt.Sprintf("[AddTask] sid or Job name is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
task.TaskType = 1
task.CreateUserId = 1
task.ModifyUserId = 1
task.CreateTime = time.Now()
task.ModifyTime = time.Now()
if s := Ss.GetScheduleById(int64(ssid)); s != nil {
err := s.AddTask(&task)
if err != nil {
e := fmt.Sprintf("[AddTask] add task error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
}
}
r.JSON(200, task)
} // }}}
示例4: AddJob
//addJob獲取客戶端發送的Job信息,並調用Schedule的AddJob方法將其
//持久化並添加至Schedule中。
//成功返回添加好的Job信息
//錯誤返回err信息
func AddJob(r render.Render, Ss *schedule.ScheduleManager, job schedule.Job) { // {{{
if job.Name == "" {
e := fmt.Sprintf("[AddJob] Job name is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if s := Ss.GetScheduleById(int64(job.ScheduleId)); s != nil {
job.ScheduleCyc = s.Cyc
job.CreateUserId = 1
job.ModifyUserId = 1
job.CreateTime = time.Now()
job.ModifyTime = time.Now()
if err := s.AddJob(&job); err != nil {
e := fmt.Sprintf("[AddJob] add job error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
} else {
r.JSON(200, job)
}
} else {
e := fmt.Sprintf("[AddJob] schedule not found.")
g.L.Warningln(e)
r.JSON(500, e)
return
}
} // }}}
示例5: DeleteJob
//調用Schedule的DeleteJob方法刪除作業
func DeleteJob(params martini.Params, r render.Render, Ss *schedule.ScheduleManager) { // {{{
sid, sidok := params["sid"]
id, idok := params["id"]
if !sidok || !idok {
e := fmt.Sprintf("[DeleteJob] sid or id not null.")
g.L.Warningln(e)
r.JSON(500, e)
return
}
ssid, _ := strconv.Atoi(sid)
iid, _ := strconv.Atoi(id)
if s := Ss.GetScheduleById(int64(ssid)); s != nil {
if err := s.DeleteJob(int64(iid)); err != nil {
e := fmt.Sprintf("[DeleteJob] delete job error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
} else {
e := fmt.Sprintf("[DeleteJob] delete job success.")
r.JSON(204, e)
}
}
} // }}}
示例6: UpdateSchedule
//updateSchedule獲取客戶端發送的Schedule信息,並調用Schedule的Update方法將其
//持久化並更新至Schedule中。
//成功返回更新後的Schedule信息
func UpdateSchedule(params martini.Params, r render.Render, Ss *schedule.ScheduleManager, scd schedule.Schedule) { // {{{
if scd.Name == "" {
e := fmt.Sprintf("[UpdateSchedule] Schedule name is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if s := Ss.GetScheduleById(int64(scd.Id)); s != nil {
s.Name, s.Desc, s.Cyc, s.StartMonth = scd.Name, scd.Desc, scd.Cyc, scd.StartMonth
s.StartSecond, s.ModifyTime, s.ModifyUserId = scd.StartSecond, time.Now(), scd.ModifyUserId
if err := s.UpdateSchedule(); err != nil {
e := fmt.Sprintf("[UpdateSchedule] update schedule error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
} else {
r.JSON(200, s)
}
} else {
e := fmt.Sprintf("[UpdateSchedule] schedule not found.")
g.L.Warningln(e)
r.JSON(500, e)
return
}
} // }}}
示例7: DeleteSchedule
func DeleteSchedule(params martini.Params, ctx *web.Context, r render.Render, Ss *schedule.ScheduleManager) { // {{{
id, _ := strconv.Atoi(params["id"])
if id == 0 {
e := fmt.Sprintf("[DeleteSchedule] id is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if err := Ss.DeleteSchedule(int64(id)); err != nil {
e := fmt.Sprintf("[DeleteSchedule] delete schedule error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
}
r.JSON(200, nil)
} // }}}
示例8: AddSchedule
//添加Schedule
func AddSchedule(params martini.Params, r render.Render, Ss *schedule.ScheduleManager, scd schedule.Schedule) { // {{{
if scd.Name == "" {
e := fmt.Sprintf("[AddSchedule] Schedule name is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
err := Ss.AddSchedule(&scd)
if err != nil {
e := fmt.Sprintf("[AddSchedule] add schedule error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
}
r.JSON(200, scd)
return
} // }}}
示例9: GetJobsForSchedule
func GetJobsForSchedule(params martini.Params, r render.Render, res http.ResponseWriter, Ss *schedule.ScheduleManager) { // {{{
sid, sidok := params["sid"]
if !sidok {
e := fmt.Sprintf("[GetJobsForSchedule] sid is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
ssid, _ := strconv.Atoi(sid)
if s := Ss.GetScheduleById(int64(ssid)); s != nil {
r.JSON(200, s.Jobs)
} else {
e := fmt.Sprintf("[GetJobsForSchedule] schedule not found.")
g.L.Warningln(e)
r.JSON(500, e)
return
}
return
} // }}}
示例10: DeleteTask
//deleteTask從調度結構中刪除指定的Task,並持久化。
func DeleteTask(params martini.Params, r render.Render, Ss *schedule.ScheduleManager) { // {{{
sid, _ := strconv.Atoi(params["sid"])
jid, _ := strconv.Atoi(params["jid"])
id, _ := strconv.Atoi(params["id"])
if sid == 0 || jid == 0 || id == 0 {
e := fmt.Sprintf("[Delete Task] sid jid id is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if s := Ss.GetScheduleById(int64(sid)); s != nil {
if err := s.DeleteTask(int64(id)); err != nil {
e := fmt.Sprintf("[Delete Task] delete task error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
} else {
r.JSON(200, nil)
}
}
} // }}}
示例11: UpdateJob
//updateJob獲取客戶端發送的Job信息,並調用Schedule的UpdateJob方法將其
//持久化並更新至Schedule中。
//成功返回更新後的Job信息
func UpdateJob(r render.Render, Ss *schedule.ScheduleManager, job schedule.Job) { // {{{
if job.Name == "" {
e := fmt.Sprintf("[UpdateJob] Job name is required")
g.L.Warningln(e)
r.JSON(500, e)
return
}
if s := Ss.GetScheduleById(int64(job.ScheduleId)); s != nil {
if err := s.UpdateJob(&job); err != nil {
e := fmt.Sprintf("[UpdateJob] update job error %s.", err.Error())
g.L.Warningln(e)
r.JSON(500, e)
return
} else {
r.JSON(200, job)
}
} else {
e := fmt.Sprintf("[UpdateJob] schedule not found.")
g.L.Warningln(e)
r.JSON(500, e)
return
}
} // }}}