void Schedule::LaunchProcess( SchedItem& si ) { EnEx ee(FL, "Schedule::LaunchProcess(const SchedItem& si)"); Date now; // Update the database to record the last-run time for this task. SqlDB& sqldb = TheMain::getInstance()->GetConfigDB( ); si.LastRun.set( now.GetValue() ); SchedItem::updateLastRun( sqldb, si.LastRun, si.id ); // Launch the task within our system xmlDocPtr doc; if(si.InputDocument.length() != 0){ doc = xmlParseDoc( si.InputDocument ); } else { doc = xmlNewDoc((const xmlChar*)"1.0"); doc->children = xmlNewDocNode( doc, NULL, (const xmlChar*)"Empty", NULL ); } dptr<SchedConn> sc = new SchedConn( si.TaskUrl, doc ); TheMain::getInstance()->getIOQueue().push( sc.release() ); }
bool Schedule::MatchesTime( const SchedItem& si, Date& now ) { EnEx ee(FL, "Schedule::MatchesTime(const SchedItem& si, Date& now)"); // Are we active? if(si.isActive == 0){ // nope. Bail out early. return false; } // Check to see if today matches the day of week filters. If not, then don't bother // checking the other stuff if(now.DayW() == 0 && si.dowSunday == 0) return false; // It's sunday and we don't run on sundays. if(now.DayW() == 1 && si.dowMonday == 0) return false; // It's monday and we don't run on mondays. if(now.DayW() == 2 && si.dowTuesday == 0) return false; // It's tuesday and we don't run on tuesdays. if(now.DayW() == 3 && si.dowWednesday == 0) return false; // It's wednesday and we don't run on wednesdays. if(now.DayW() == 4 && si.dowThursday == 0) return false; // It's thursday and we don't run on thursdays. if(now.DayW() == 5 && si.dowFriday == 0) return false; // It's friday and we don't run on fridays. if(now.DayW() == 6 && si.dowSaturday == 0) return false; // It's saturday and we don't run on saturdays. // Are we a runEvery, or a runAtTime: if(si.useInterval){ // We are a runEvery. Check our LastRun time: if(si.LastRun.length() == 0){ // We've never been run. Time to get started. DEBUG(FL, "%s: Interval check: si.LastRun.length() == 0 - return true", si.TaskName()); return true; } Date lastRunDate; lastRunDate.SetValue( si.LastRun ); Interval diff = now.operator-(lastRunDate); if( diff.Sec() >= (si.runEvery * 60)){ // runEvery is measured in minutes DEBUG(FL, "%s: Interval check: LastRun(%s) Now(%s) RunEvery(%d) - return true", si.TaskName(), si.LastRun(), now.GetValue(), si.runEvery ); return true; // time to run. } else { DEBUG(FL, "%s: Interval check: LastRun(%s) Now(%s) RunEvery(%d) - return false", si.TaskName(), si.LastRun(), now.GetValue(), si.runEvery ); return false; // not yet. } } else { // We are a runAtTime. Check the time now, vs. the time we are supposed to run. if(si.RunAtTime.length() < 4){ WARN(FL, "Schedule entry %s has an invalid RunAtTime setting.", si.TaskName() ); return false; } twine hours = si.RunAtTime.substr(0, 2); twine mins = si.RunAtTime.substr(2); if(hours.get_int() == now.Hour() && mins.get_int() == now.Min() ){ DEBUG(FL, "%s: RunAtTime check: (%s) Now (%s) - return true", si.TaskName(), si.RunAtTime(), now.GetValue() ); return true; } else { DEBUG(FL, "%s: RunAtTime check: (%s) Now (%s) - return false", si.TaskName(), si.RunAtTime(), now.GetValue() ); return false; } } }
int main (void) { Date ad; Date bd; Date cd; printf("ad is (%s)\n", ad.GetValue()()); printf("ad is also (%s)\n", ad.GetValue("%Y-%m-%d-%H-%M-%S")()); bd.SetValue("07/13/2001 01:02:03.456", "%m/%d/%Y %H:%M:%S"); printf("bd is (%s)\n", bd.GetValue()()); printf("bd is also (%s)\n", bd.GetValue("%m/%d/%Y %H:%M:%S")()); printf("bd is also (%s)\n", bd.GetValue("%Y%m%d%H%M%S")()); printf("bd is also (%s)\n", bd.EDate()()); printf("bd is also (%s)\n", bd.EDate()()); printf("bd is also (%s)\n", bd.EDate()()); printf("bd is also (%s)\n", bd.EDate()()); twine tmp, tmp2; tmp2 = bd.EDate(); tmp.format("Date: %s\r\n", tmp2() ); printf("%s\n", tmp()); printf("Before direct format\n"); tmp.format("Date: %s\r\n", bd.GetValue("%Y%m%d%H%M%S")() ); printf("After direct format\n"); printf("%s", tmp() ); printf("Before EDate format\n"); tmp.format("Date: %s\r\n", bd.EDate()() ); printf("After EDate format\n"); printf("%s", tmp() ); ad.Floor(); bd = ad; bd.Ceil(); printf("ad is (%s) bd is (%s)\n", ad.GetValue()(), bd.GetValue()()); cd.SetValue("7/4/2001", "%m/%d/%Y"); printf("cd is (%s)\n", cd.GetValue()()); cd.SetValue("7/4/89", "%m/%d/%Y"); printf("cd is (%s)\n", cd.GetValue()()); cd.SetValue("7/4/01", "%m/%d/%Y"); printf("cd is (%s)\n", cd.GetValue()()); cd.SetValue("20010714080910.123", "%Y%m%d%H%M%S"); printf("cd is (%s)\n", cd.GetValue()()); cd.SetValue("2001/09/01 00:08:05"); printf("Initial cd is (%s)\n", cd.GetValue()()); cd.AddSec(-65); printf("cd is (%s)\n", cd.GetValue()()); ad.SetValue("2001/08/09 12:00:00"); bd.SetValue("2001/08/09 12:30:00"); if(bd - ad > SLib::Interval(10, MINUTES)){ printf("(%s) - (%s) has a difference greater than 10 minutes\n", bd.GetValue()(), ad.GetValue()()); } if(bd - ad > SLib::Interval(20, MINUTES)){ printf("(%s) - (%s) has a difference greater than 20 minutes\n", bd.GetValue()(), ad.GetValue()()); } if(bd - ad > SLib::Interval(1, DAY)){ printf("(%s) - (%s) has a difference greater than 1 day\n", bd.GetValue()(), ad.GetValue()()); } test_conversions(); return 0; }