job scheduler works with run once and run periodic schedules. Stop logic is not fully thought through.
Dependents: JobSchedulerDemo Borsch
Diff: scheduler.cpp
- Revision:
- 6:5baa0e4ec500
- Parent:
- 5:d8f69ac330f2
- Child:
- 7:98c8b2eabea3
--- a/scheduler.cpp Tue Jul 11 22:35:33 2017 +0000 +++ b/scheduler.cpp Tue Jul 11 22:42:08 2017 +0000 @@ -69,6 +69,18 @@ Response<JobID> Scheduler::reschedule(Appointment *apt) { JobAddReq req(apt); + + // set next appointment time + time_t now = time(NULL); // now in seconds + apt->SetTime(apt->GetJob()->GetSchedule()->NextRunTime(now)); + if (apt->GetTime() == 0) { + // there is no next run time; delete appointment + printf("[Scheduler::reschedule] NO next appointment\n"); + delete apt; + req.response.error = 2; + return req.response; + } + printf("[Scheduler::reschedule] put\n"); _updates.put(&req); printf("[Scheduler::reschedule] get\n"); @@ -125,8 +137,6 @@ // assign job its ID job->Init(_nextJobID++); } - // set next appointment time - req->apt->SetTime(job->GetSchedule()->NextRunTime(now)); node<Appointment> *tmp = _timeline.insertOrdered(req->apt, descendingTimeline); if (NULL == tmp) { printf("[Scheduler::process] timeline insert failed\n");