6 #include <QWaitCondition>
12 #include <QRecursiveMutex>
25 #define JOBSTATUS_MAP(F) \
26 F(JOB_UNKNOWN, 0x0000, JobQueue::tr("Unknown")) \
27 F(JOB_QUEUED, 0x0001, JobQueue::tr("Queued")) \
28 F(JOB_PENDING, 0x0002, JobQueue::tr("Pending")) \
29 F(JOB_STARTING, 0x0003, JobQueue::tr("Starting")) \
30 F(JOB_RUNNING, 0x0004, JobQueue::tr("Running")) \
31 F(JOB_STOPPING, 0x0005, JobQueue::tr("Stopping")) \
32 F(JOB_PAUSED, 0x0006, JobQueue::tr("Paused")) \
33 F(JOB_RETRY, 0x0007, JobQueue::tr("Retrying")) \
34 F(JOB_ERRORING, 0x0008, JobQueue::tr("Erroring")) \
35 F(JOB_ABORTING, 0x0009, JobQueue::tr("Aborting")) \
40 F(JOB_DONE, 0x0100, JobQueue::tr("Done (Invalid status!)")) \
41 F(JOB_FINISHED, 0x0110, JobQueue::tr("Finished")) \
42 F(JOB_ABORTED, 0x0120, JobQueue::tr("Aborted")) \
43 F(JOB_ERRORED, 0x0130, JobQueue::tr("Errored")) \
44 F(JOB_CANCELLED, 0x0140, JobQueue::tr("Cancelled")) \
46 #define JOBSTATUS_ENUM(A,B,C) A = (B) ,
135 friend class QueueProcessorThread;
139 void customEvent(QEvent *e)
override;
141 static bool QueueRecordingJobs(
144 const QDateTime &recstartts,
const QString&
args =
"",
145 const QString& comment =
"", QString host =
"",
146 int flags = 0,
int status = JOB_QUEUED,
147 QDateTime schedruntime = QDateTime());
149 static bool QueueJobs(
int jobTypes,
uint chanid,
150 const QDateTime &recstartts,
const QString&
args =
"",
151 const QString& comment =
"",
const QString& host =
"");
153 static int GetJobID(
int jobType,
uint chanid,
154 const QDateTime &recstartts);
155 static bool GetJobInfoFromID(
int jobID,
int &jobType,
156 uint &chanid, QDateTime &recstartts);
157 static bool GetJobInfoFromID(
int jobID,
int &jobType,
158 uint &chanid, QString &recstartts);
159 static int GetJobTypeFromName(
const QString &name);
161 static bool ChangeJobCmds(
int jobID,
int newCmds);
162 static bool ChangeJobCmds(
int jobType,
uint chanid,
163 const QDateTime &recstartts,
int newCmds);
164 static bool ChangeJobFlags(
int jobID,
int newFlags);
165 static bool ChangeJobStatus(
int jobID,
int newStatus,
166 const QString& comment =
"");
167 static bool ChangeJobHost(
int jobID,
const QString& newHostname);
168 static bool ChangeJobComment(
int jobID,
169 const QString& comment =
"");
170 static bool ChangeJobArgs(
int jobID,
171 const QString&
args =
"");
172 static bool IsJobQueuedOrRunning(
int jobType,
uint chanid,
173 const QDateTime &recstartts);
174 int GetRunningJobID(
uint chanid,
const QDateTime &recstartts);
175 static bool IsJobRunning(
int jobType,
uint chanid,
176 const QDateTime &recstartts);
177 static bool IsJobRunning(
int jobType,
const ProgramInfo &pginfo);
178 static bool IsJobQueued(
int jobType,
179 uint chanid,
const QDateTime &recstartts);
180 static bool IsJobStatusQueued(
int status);
181 static bool IsJobStatusRunning(
int status);
182 static bool PauseJob(
int jobID);
183 static bool ResumeJob(
int jobID);
184 static bool RestartJob(
int jobID);
185 static bool StopJob(
int jobID);
186 static bool DeleteJob(
int jobID);
187 static bool SafeDeleteJob(
int jobID,
int jobType,
int chanid,
188 const QDateTime& recstartts);
194 const QDateTime &recstartts);
195 static QString GetJobArgs(
int jobID);
196 static int UserJobTypeToIndex(
int JobType);
198 static bool DeleteAllJobs(
uint chanid,
const QDateTime &recstartts);
200 static void ClearJobMask(
int &mask) { mask =
JOB_NONE; }
201 static bool JobIsInMask(
int job,
int mask) {
return (
bool)(job & mask); }
202 static bool JobIsNotInMask(
int job,
int mask)
203 {
return ! JobIsInMask(job, mask); }
204 static void AddJobsToMask(
int jobs,
int &mask) { mask |= jobs; }
205 static void RemoveJobsFromMask(
int jobs,
int &mask) { mask &= ~jobs; }
207 static QString JobText(
int jobType);
208 static QString StatusText(
int status);
210 static bool HasRunningOrPendingJobs(std::chrono::minutes startingWithinMins = 0min);
212 static int GetJobsInQueue(QMap<int, JobQueueEntry> &jobs,
215 static void RecoverQueue(
bool justOld =
false);
216 static void RecoverOldJobsInQueue()
217 { RecoverQueue(
true); }
218 static void CleanupOldJobsInQueue();
220 static bool InJobRunWindow(QDateTime jobstarttsRaw);
229 void run(
void)
override;
230 void ProcessQueue(
void);
236 static bool InJobRunWindow(std::chrono::minutes orStartsWithinMins = 0min);
238 void StartChildJob(
void *(*ChildThreadRoutine)(
void *),
int jobID);
240 static QString GetJobDescription(
int jobType);
241 static QString GetJobCommand(
int id,
int jobType,
ProgramInfo *tmpInfo);
242 void RemoveRunningJob(
int id);
246 static void *TranscodeThread(
void *param);
247 void DoTranscodeThread(
int jobID);
249 static void *MetadataLookupThread(
void *param);
250 void DoMetadataLookupThread(
int jobID);
252 static void *FlagCommercialsThread(
void *param);
253 void DoFlagCommercialsThread(
int jobID);
255 static void *UserJobThread(
void *param);
256 void DoUserJobThread(
int jobID);
260 int m_jobsRunning {0};
261 int m_jobQueueCPU {0};
268 QRecursiveMutex *m_runningJobsLock {
nullptr};
269 QMap<int, RunningJobInfo> m_runningJobs;
274 QWaitCondition m_queueThreadCond;
275 QMutex m_queueThreadCondLock;
276 bool m_processQueue {
false};