Ticket #3403: shutdown-jobs.diff
File shutdown-jobs.diff, 10.6 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/jobqueue.cpp
168 168 169 169 QMap<QString, int> jobStatus; 170 170 int maxJobs; 171 QString queueStartTimeStr;172 QString queueEndTimeStr;173 int queueStartTime;174 int queueEndTime;175 QTime curQTime;176 int curTime;177 171 QString message; 178 QString tmpStr;179 172 QMap<int, JobQueueEntry> jobs; 180 173 bool atMax = false; 181 174 bool inTimeWindow = true; … … 187 180 188 181 startedJobAlready = false; 189 182 sleepTime = gContext->GetNumSetting("JobQueueCheckFrequency", 30); 190 queueStartTimeStr =191 gContext->GetSetting("JobQueueWindowStart", "00:00");192 queueEndTimeStr =193 gContext->GetSetting("JobQueueWindowEnd", "23:59");194 195 183 maxJobs = gContext->GetNumSetting("JobQueueMaxSimultaneousJobs", 3); 196 184 VERBOSE(VB_JOBQUEUE, LOC + 197 QString("Currently set at %1 job(s) max and to run new jobs " 198 "from %2 to %3").arg(maxJobs).arg(queueStartTimeStr) 199 .arg(queueEndTimeStr)); 185 QString("Currently set to run up to %1 job(s) max.") 186 .arg(maxJobs)); 200 187 201 188 jobStatus.clear(); 202 189 … … 204 191 205 192 if (jobs.size()) 206 193 { 207 tmpStr = queueStartTimeStr; 208 queueStartTime = tmpStr.replace(QRegExp(":"), "").toInt(); 209 tmpStr = queueEndTimeStr; 210 queueEndTime = tmpStr.replace(QRegExp(":"), "").toInt(); 211 curQTime = QTime::currentTime(); 212 curTime = curQTime.hour() * 100 + curQTime.minute(); 213 inTimeWindow = false; 214 215 if ((queueStartTime <= curTime) && (curTime < queueEndTime)) 216 { 217 inTimeWindow = true; 218 } 219 else if ((queueStartTime > queueEndTime) && 220 ((curTime < queueEndTime) || (queueStartTime <= curTime))) 221 { 222 inTimeWindow = true; 223 } 224 194 inTimeWindow = InJobRunWindow(); 225 195 jobsRunning = 0; 226 196 for (unsigned int x = 0; x < jobs.size(); x++) 227 197 { … … 241 211 { 242 212 message += QString(" Jobs in Queue, but we are outside of the " 243 213 "Job Queue time window, no new jobs can be " 244 "started, next window starts at %1.") 245 .arg(queueStartTimeStr); 214 "started."); 246 215 VERBOSE(VB_JOBQUEUE, LOC + message); 247 216 } 248 217 else if (jobsRunning >= maxJobs) … … 1121 1090 return JobQueue::GetJobQueueKey(pginfo->chanid, pginfo->recstartts); 1122 1091 } 1123 1092 1093 bool JobQueue::InJobRunWindow(int orStartsWithinMins) 1094 { 1095 QString queueStartTimeStr; 1096 QString queueEndTimeStr; 1097 QTime queueStartTime; 1098 QTime queueEndTime; 1099 QTime curTime = QTime::currentTime(); 1100 bool inTimeWindow = false; 1101 orStartsWithinMins = orStartsWithinMins < 0 ? 0 : orStartsWithinMins; 1102 1103 queueStartTimeStr = gContext->GetSetting("JobQueueWindowStart", "00:00"); 1104 queueEndTimeStr = gContext->GetSetting("JobQueueWindowEnd", "23:59"); 1105 1106 VERBOSE(VB_JOBQUEUE, LOC + 1107 QString("Currently set to run new jobs from %1 to %2") 1108 .arg(queueStartTimeStr).arg(queueEndTimeStr)); 1109 1110 queueStartTime = QTime::fromString(queueStartTimeStr); 1111 if (!queueStartTime.isValid()) 1112 { 1113 VERBOSE(VB_IMPORTANT, "Invalid JobQueueWindowStart time, using 00:00"); 1114 queueStartTime = QTime::QTime(0, 0); 1115 } 1116 1117 queueEndTime = QTime::fromString(queueEndTimeStr); 1118 if (!queueEndTime.isValid()) 1119 { 1120 VERBOSE(VB_IMPORTANT, "Invalid JobQueueWindowEnd time, using 23:59"); 1121 queueEndTime = QTime::QTime(23, 59); 1122 } 1123 1124 if ((queueStartTime <= curTime) && (curTime < queueEndTime)) 1125 { 1126 inTimeWindow = true; 1127 } 1128 else if ((queueStartTime > queueEndTime) && 1129 ((curTime < queueEndTime) || (queueStartTime <= curTime))) 1130 { 1131 inTimeWindow = true; 1132 } 1133 else if (orStartsWithinMins > 0) 1134 { 1135 // Check if the window starts soon 1136 if (curTime <= queueStartTime) 1137 { 1138 // Start time hasn't passed yet today 1139 if (queueStartTime.secsTo(curTime) <= (orStartsWithinMins * 60)) 1140 { 1141 VERBOSE(VB_JOBQUEUE, LOC + 1142 QString("Job run window will start within %1 minutes") 1143 .arg(orStartsWithinMins)); 1144 inTimeWindow = true; 1145 } 1146 } 1147 else 1148 { 1149 // We passed the start time for today, try tomorrow 1150 QDateTime curDateTime = QDateTime::currentDateTime(); 1151 QDateTime startDateTime = QDateTime(QDate::currentDate(), queueStartTime).addDays(1); 1152 1153 if (curDateTime.secsTo(startDateTime) <= (orStartsWithinMins * 60)) 1154 { 1155 VERBOSE(VB_JOBQUEUE, LOC + 1156 QString("Job run window will start within %1 minutes (tomorrow)") 1157 .arg(orStartsWithinMins)); 1158 inTimeWindow = true; 1159 } 1160 } 1161 } 1162 1163 return inTimeWindow; 1164 } 1165 1166 bool JobQueue::HasRunningOrPendingJobs(int startingWithinMins) 1167 { 1168 /* startingWithinMins <= 0 - look for any pending jobs 1169 > 0 - only consider pending starting within this time */ 1170 QMap<int, JobQueueEntry> jobs; 1171 QMap<int, JobQueueEntry>::Iterator it; 1172 QDateTime maxSchedRunTime = QDateTime::currentDateTime(); 1173 int tmpStatus = 0; 1174 bool checkForQueuedJobs = (startingWithinMins <= 0 1175 || InJobRunWindow(startingWithinMins)); 1176 1177 if (checkForQueuedJobs && startingWithinMins > 0) { 1178 maxSchedRunTime = maxSchedRunTime.addSecs(startingWithinMins * 60); 1179 VERBOSE(VB_JOBQUEUE, LOC + 1180 QString("HasRunningOrPendingJobs: checking for jobs " 1181 "starting before: %1").arg(maxSchedRunTime.toString())); 1182 } 1183 1184 JobQueue::GetJobsInQueue(jobs, JOB_LIST_NOT_DONE); 1185 1186 if (jobs.size()) { 1187 for (it = jobs.begin(); it != jobs.end(); ++it) 1188 { 1189 tmpStatus = it.data().status; 1190 if (tmpStatus == JOB_RUNNING) { 1191 VERBOSE(VB_JOBQUEUE, LOC + 1192 QString("HasRunningOrPendingJobs: found running job")); 1193 return true; 1194 } 1195 1196 if (checkForQueuedJobs) { 1197 if ((tmpStatus != JOB_UNKNOWN) && (!(tmpStatus & JOB_DONE))) { 1198 if (startingWithinMins <= 0) { 1199 VERBOSE(VB_JOBQUEUE, LOC + 1200 QString("HasRunningOrPendingJobs: " 1201 "found pending job")); 1202 return true; 1203 } 1204 else if (it.data().schedruntime <= maxSchedRunTime) { 1205 VERBOSE(VB_JOBQUEUE, LOC + 1206 QString("HasRunningOrPendingJobs: found pending " 1207 "job scheduled to start at: %1") 1208 .arg(it.data().schedruntime.toString())); 1209 return true; 1210 } 1211 } 1212 } 1213 } 1214 } 1215 return false; 1216 } 1217 1218 1124 1219 int JobQueue::GetJobsInQueue(QMap<int, JobQueueEntry> &jobs, int findJobs) 1125 1220 { 1126 1221 JobQueueEntry thisJob; -
libs/libmythtv/jobqueue.h
161 161 static QString JobText(int jobType); 162 162 static QString StatusText(int status); 163 163 164 static bool HasRunningOrPendingJobs(int startingWithinMins = 0); 165 164 166 static int GetJobsInQueue(QMap<int, JobQueueEntry> &jobs, 165 167 int findJobs = JOB_LIST_NOT_DONE); 166 168 … … 178 180 179 181 bool AllowedToRun(JobQueueEntry job); 180 182 183 static bool InJobRunWindow(int orStartingWithinMins = 0); 184 181 185 void StartChildJob(void *(*start_routine)(void *), ProgramInfo *tmpInfo); 182 186 183 187 static QString GetJobQueueKey(QString chanid, QString startts); -
programs/mythwelcome/welcomedialog.cpp
633 633 m_statusList.append(tr("MythTV is busy grabbing EPG data.")); 634 634 if (statusCode & 16) 635 635 m_statusList.append(tr("MythTV is locked by a user.")); 636 if (statusCode & 32) 637 m_statusList.append(tr("MythTV is has running or pending jobs.")); 636 638 if (statusCode & 64) 637 639 m_statusList.append(tr("MythTV is in a daily wakeup/shutdown period.")); 638 640 if (statusCode & 128) -
programs/mythshutdown/main.cpp
12 12 #include <mythcontext.h> 13 13 #include <mythdbcon.h> 14 14 #include "libmythtv/programinfo.h" 15 #include "libmythtv/jobqueue.h" 15 16 #include "tv.h" 16 17 17 18 void setGlobalSetting(const QString &key, const QString &value) … … 201 202 res += 16; 202 203 } 203 204 205 if (JobQueue::HasRunningOrPendingJobs(15)) 206 { 207 VERBOSE(VB_IMPORTANT, "Has queued or pending jobs"); 208 res += 32; 209 } 210 204 211 QDateTime dtPeriod1Start = getDailyWakeupTime("DailyWakeupStartPeriod1"); 205 212 QDateTime dtPeriod1End = getDailyWakeupTime("DailyWakeupEndPeriod1"); 206 213 QDateTime dtPeriod2Start = getDailyWakeupTime("DailyWakeupStartPeriod2"); … … 715 722 cout << " 4 - Grabbing EPG data\n"; 716 723 cout << " 8 - Recording - only valid if flag is 1\n"; 717 724 cout << " 16 - Locked\n"; 718 cout << " 32 - Not used\n";725 cout << " 32 - Jobs running or pending\n"; 719 726 cout << " 64 - In a daily wakeup/shutdown period\n"; 720 727 cout << " 128 - Less than 15 minutes to next wakeup period\n"; 721 728 cout << "-v/--verbose debug-level (Use '-v help' for level info\n";