6 #include <QWaitCondition>
21 #define JOBSTATUS_MAP(F) \
22 F(JOB_UNKNOWN, 0x0000, JobQueue::tr("Unknown")) \
23 F(JOB_QUEUED, 0x0001, JobQueue::tr("Queued")) \
24 F(JOB_PENDING, 0x0002, JobQueue::tr("Pending")) \
25 F(JOB_STARTING, 0x0003, JobQueue::tr("Starting")) \
26 F(JOB_RUNNING, 0x0004, JobQueue::tr("Running")) \
27 F(JOB_STOPPING, 0x0005, JobQueue::tr("Stopping")) \
28 F(JOB_PAUSED, 0x0006, JobQueue::tr("Paused")) \
29 F(JOB_RETRY, 0x0007, JobQueue::tr("Retrying")) \
30 F(JOB_ERRORING, 0x0008, JobQueue::tr("Erroring")) \
31 F(JOB_ABORTING, 0x0009, JobQueue::tr("Aborting")) \
36 F(JOB_DONE, 0x0100, JobQueue::tr("Done (Invalid status!)")) \
37 F(JOB_FINISHED, 0x0110, JobQueue::tr("Finished")) \
38 F(JOB_ABORTED, 0x0120, JobQueue::tr("Aborted")) \
39 F(JOB_ERRORED, 0x0130, JobQueue::tr("Errored")) \
40 F(JOB_CANCELLED, 0x0140, JobQueue::tr("Cancelled")) \
43 #define JOBSTATUS_ENUM(A,B,C) A = (B) ,
129 friend class QueueProcessorThread;
133 void customEvent(QEvent *
e)
override;
135 static bool QueueRecordingJobs(
138 const QDateTime &recstartts,
const QString&
args =
"",
139 const QString& comment =
"", QString host =
"",
140 int flags = 0,
int status = JOB_QUEUED,
141 QDateTime schedruntime = QDateTime());
143 static bool QueueJobs(
int jobTypes,
uint chanid,
144 const QDateTime &recstartts,
const QString&
args =
"",
145 const QString& comment =
"",
const QString& host =
"");
147 static int GetJobID(
int jobType,
uint chanid,
148 const QDateTime &recstartts);
149 static bool GetJobInfoFromID(
int jobID,
int &jobType,
150 uint &chanid, QDateTime &recstartts);
151 static bool GetJobInfoFromID(
int jobID,
int &jobType,
152 uint &chanid, QString &recstartts);
153 static int GetJobTypeFromName(
const QString &name);
155 static bool ChangeJobCmds(
int jobID,
int newCmds);
156 static bool ChangeJobCmds(
int jobType,
uint chanid,
157 const QDateTime &recstartts,
int newCmds);
158 static bool ChangeJobFlags(
int jobID,
int newFlags);
159 static bool ChangeJobStatus(
int jobID,
int newStatus,
160 const QString& comment =
"");
161 static bool ChangeJobHost(
int jobID,
const QString& newHostname);
162 static bool ChangeJobComment(
int jobID,
163 const QString& comment =
"");
164 static bool ChangeJobArgs(
int jobID,
165 const QString&
args =
"");
166 static bool IsJobQueuedOrRunning(
int jobType,
uint chanid,
167 const QDateTime &recstartts);
168 int GetRunningJobID(
uint chanid,
const QDateTime &recstartts);
169 static bool IsJobRunning(
int jobType,
uint chanid,
170 const QDateTime &recstartts);
171 static bool IsJobRunning(
int jobType,
const ProgramInfo &pginfo);
172 static bool IsJobQueued(
int jobType,
173 uint chanid,
const QDateTime &recstartts);
174 static bool IsJobStatusQueued(
int status);
175 static bool IsJobStatusRunning(
int status);
176 static bool PauseJob(
int jobID);
177 static bool ResumeJob(
int jobID);
178 static bool RestartJob(
int jobID);
179 static bool StopJob(
int jobID);
180 static bool DeleteJob(
int jobID);
181 static bool SafeDeleteJob(
int jobID,
int jobType,
int chanid,
182 const QDateTime& recstartts);
188 const QDateTime &recstartts);
189 static QString GetJobArgs(
int jobID);
190 static int UserJobTypeToIndex(
int JobType);
192 static bool DeleteAllJobs(
uint chanid,
const QDateTime &recstartts);
194 static void ClearJobMask(
int &mask) { mask =
JOB_NONE; }
195 static bool JobIsInMask(
int job,
int mask) {
return (
bool)(job & mask); }
196 static bool JobIsNotInMask(
int job,
int mask)
197 {
return ! JobIsInMask(job, mask); }
198 static void AddJobsToMask(
int jobs,
int &mask) { mask |= jobs; }
199 static void RemoveJobsFromMask(
int jobs,
int &mask) { mask &= ~jobs; }
201 static QString JobText(
int jobType);
202 static QString StatusText(
int status);
204 static bool HasRunningOrPendingJobs(
int startingWithinMins = 0);
206 static int GetJobsInQueue(QMap<int, JobQueueEntry> &jobs,
209 static void RecoverQueue(
bool justOld =
false);
210 static void RecoverOldJobsInQueue()
211 { RecoverQueue(
true); }
212 static void CleanupOldJobsInQueue();
214 static bool InJobRunWindow(QDateTime jobstarttsRaw);
223 void run(
void)
override;
224 void ProcessQueue(
void);
230 static bool InJobRunWindow(
int orStartsWithinMins = 0);
232 void StartChildJob(
void *(*ChildThreadRoutine)(
void *),
int jobID);
234 static QString GetJobDescription(
int jobType);
235 static QString GetJobCommand(
int id,
int jobType,
ProgramInfo *tmpInfo);
236 void RemoveRunningJob(
int id);
240 static void *TranscodeThread(
void *param);
241 void DoTranscodeThread(
int jobID);
243 static void *MetadataLookupThread(
void *param);
244 void DoMetadataLookupThread(
int jobID);
246 static void *FlagCommercialsThread(
void *param);
247 void DoFlagCommercialsThread(
int jobID);
249 static void *UserJobThread(
void *param);
250 void DoUserJobThread(
int jobID);
254 int m_jobsRunning {0};
255 int m_jobQueueCPU {0};
262 QMutex *m_runningJobsLock {
nullptr};
263 QMap<int, RunningJobInfo> m_runningJobs;
268 QWaitCondition m_queueThreadCond;
269 QMutex m_queueThreadCondLock;
270 bool m_processQueue {
false};