6 #include <QWaitCondition>
12 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
13 #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")) \
47 #define JOBSTATUS_ENUM(A,B,C) A = (B) ,
133 friend class QueueProcessorThread;
137 void customEvent(QEvent *e)
override;
139 static bool QueueRecordingJobs(
142 const QDateTime &recstartts,
const QString&
args =
"",
143 const QString& comment =
"", QString host =
"",
144 int flags = 0,
int status = JOB_QUEUED,
145 QDateTime schedruntime = QDateTime());
147 static bool QueueJobs(
int jobTypes,
uint chanid,
148 const QDateTime &recstartts,
const QString&
args =
"",
149 const QString& comment =
"",
const QString& host =
"");
151 static int GetJobID(
int jobType,
uint chanid,
152 const QDateTime &recstartts);
153 static bool GetJobInfoFromID(
int jobID,
int &jobType,
154 uint &chanid, QDateTime &recstartts);
155 static bool GetJobInfoFromID(
int jobID,
int &jobType,
156 uint &chanid, QString &recstartts);
157 static int GetJobTypeFromName(
const QString &name);
159 static bool ChangeJobCmds(
int jobID,
int newCmds);
160 static bool ChangeJobCmds(
int jobType,
uint chanid,
161 const QDateTime &recstartts,
int newCmds);
162 static bool ChangeJobFlags(
int jobID,
int newFlags);
163 static bool ChangeJobStatus(
int jobID,
int newStatus,
164 const QString& comment =
"");
165 static bool ChangeJobHost(
int jobID,
const QString& newHostname);
166 static bool ChangeJobComment(
int jobID,
167 const QString& comment =
"");
168 static bool ChangeJobArgs(
int jobID,
169 const QString&
args =
"");
170 static bool IsJobQueuedOrRunning(
int jobType,
uint chanid,
171 const QDateTime &recstartts);
172 int GetRunningJobID(
uint chanid,
const QDateTime &recstartts);
173 static bool IsJobRunning(
int jobType,
uint chanid,
174 const QDateTime &recstartts);
175 static bool IsJobRunning(
int jobType,
const ProgramInfo &pginfo);
176 static bool IsJobQueued(
int jobType,
177 uint chanid,
const QDateTime &recstartts);
178 static bool IsJobStatusQueued(
int status);
179 static bool IsJobStatusRunning(
int status);
180 static bool PauseJob(
int jobID);
181 static bool ResumeJob(
int jobID);
182 static bool RestartJob(
int jobID);
183 static bool StopJob(
int jobID);
184 static bool DeleteJob(
int jobID);
185 static bool SafeDeleteJob(
int jobID,
int jobType,
int chanid,
186 const QDateTime& recstartts);
192 const QDateTime &recstartts);
193 static QString GetJobArgs(
int jobID);
194 static int UserJobTypeToIndex(
int JobType);
196 static bool DeleteAllJobs(
uint chanid,
const QDateTime &recstartts);
198 static void ClearJobMask(
int &mask) { mask =
JOB_NONE; }
199 static bool JobIsInMask(
int job,
int mask) {
return (
bool)(job & mask); }
200 static bool JobIsNotInMask(
int job,
int mask)
201 {
return ! JobIsInMask(job, mask); }
202 static void AddJobsToMask(
int jobs,
int &mask) { mask |= jobs; }
203 static void RemoveJobsFromMask(
int jobs,
int &mask) { mask &= ~jobs; }
205 static QString JobText(
int jobType);
206 static QString StatusText(
int status);
208 static bool HasRunningOrPendingJobs(std::chrono::minutes startingWithinMins = 0min);
210 static int GetJobsInQueue(QMap<int, JobQueueEntry> &jobs,
213 static void RecoverQueue(
bool justOld =
false);
214 static void RecoverOldJobsInQueue()
215 { RecoverQueue(
true); }
216 static void CleanupOldJobsInQueue();
218 static bool InJobRunWindow(QDateTime jobstarttsRaw);
227 void run(
void)
override;
228 void ProcessQueue(
void);
234 static bool InJobRunWindow(std::chrono::minutes orStartsWithinMins = 0min);
236 void StartChildJob(
void *(*ChildThreadRoutine)(
void *),
int jobID);
238 static QString GetJobDescription(
int jobType);
239 static QString GetJobCommand(
int id,
int jobType,
ProgramInfo *tmpInfo);
240 void RemoveRunningJob(
int id);
244 static void *TranscodeThread(
void *param);
245 void DoTranscodeThread(
int jobID);
247 static void *MetadataLookupThread(
void *param);
248 void DoMetadataLookupThread(
int jobID);
250 static void *FlagCommercialsThread(
void *param);
251 void DoFlagCommercialsThread(
int jobID);
253 static void *UserJobThread(
void *param);
254 void DoUserJobThread(
int jobID);
258 int m_jobsRunning {0};
259 int m_jobQueueCPU {0};
266 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
267 QMutex *m_runningJobsLock {
nullptr};
269 QRecursiveMutex *m_runningJobsLock {
nullptr};
271 QMap<int, RunningJobInfo> m_runningJobs;
276 QWaitCondition m_queueThreadCond;
277 QMutex m_queueThreadCondLock;
278 bool m_processQueue {
false};