6 #include <QWaitCondition>
12 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
13 #include <QRecursiveMutex>
27 #define JOBSTATUS_MAP(F) \
28 F(JOB_UNKNOWN, 0x0000, JobQueue::tr("Unknown")) \
29 F(JOB_QUEUED, 0x0001, JobQueue::tr("Queued")) \
30 F(JOB_PENDING, 0x0002, JobQueue::tr("Pending")) \
31 F(JOB_STARTING, 0x0003, JobQueue::tr("Starting")) \
32 F(JOB_RUNNING, 0x0004, JobQueue::tr("Running")) \
33 F(JOB_STOPPING, 0x0005, JobQueue::tr("Stopping")) \
34 F(JOB_PAUSED, 0x0006, JobQueue::tr("Paused")) \
35 F(JOB_RETRY, 0x0007, JobQueue::tr("Retrying")) \
36 F(JOB_ERRORING, 0x0008, JobQueue::tr("Erroring")) \
37 F(JOB_ABORTING, 0x0009, JobQueue::tr("Aborting")) \
42 F(JOB_DONE, 0x0100, JobQueue::tr("Done (Invalid status!)")) \
43 F(JOB_FINISHED, 0x0110, JobQueue::tr("Finished")) \
44 F(JOB_ABORTED, 0x0120, JobQueue::tr("Aborted")) \
45 F(JOB_ERRORED, 0x0130, JobQueue::tr("Errored")) \
46 F(JOB_CANCELLED, 0x0140, JobQueue::tr("Cancelled")) \
48 #define JOBSTATUS_ENUM(A,B,C) A = (B) ,
137 friend class QueueProcessorThread;
141 void customEvent(QEvent *e)
override;
143 static bool QueueRecordingJobs(
146 const QDateTime &recstartts,
const QString&
args =
"",
147 const QString& comment =
"", QString host =
"",
148 int flags = 0,
int status = JOB_QUEUED,
149 QDateTime schedruntime = QDateTime());
151 static bool QueueJobs(
int jobTypes,
uint chanid,
152 const QDateTime &recstartts,
const QString&
args =
"",
153 const QString& comment =
"",
const QString& host =
"");
155 static int GetJobID(
int jobType,
uint chanid,
156 const QDateTime &recstartts);
157 static bool GetJobInfoFromID(
int jobID,
int &jobType,
158 uint &chanid, QDateTime &recstartts);
159 static bool GetJobInfoFromID(
int jobID,
int &jobType,
160 uint &chanid, QString &recstartts);
161 static int GetJobTypeFromName(
const QString &name);
163 static bool ChangeJobCmds(
int jobID,
int newCmds);
164 static bool ChangeJobCmds(
int jobType,
uint chanid,
165 const QDateTime &recstartts,
int newCmds);
166 static bool ChangeJobFlags(
int jobID,
int newFlags);
167 static bool ChangeJobStatus(
int jobID,
int newStatus,
168 const QString& comment =
"");
169 static bool ChangeJobHost(
int jobID,
const QString& newHostname);
170 static bool ChangeJobComment(
int jobID,
171 const QString& comment =
"");
172 static bool ChangeJobArgs(
int jobID,
173 const QString&
args =
"");
174 static bool IsJobQueuedOrRunning(
int jobType,
uint chanid,
175 const QDateTime &recstartts);
176 int GetRunningJobID(
uint chanid,
const QDateTime &recstartts);
177 static bool IsJobRunning(
int jobType,
uint chanid,
178 const QDateTime &recstartts);
179 static bool IsJobRunning(
int jobType,
const ProgramInfo &pginfo);
180 static bool IsJobQueued(
int jobType,
181 uint chanid,
const QDateTime &recstartts);
182 static bool IsJobStatusQueued(
int status);
183 static bool IsJobStatusRunning(
int status);
184 static bool PauseJob(
int jobID);
185 static bool ResumeJob(
int jobID);
186 static bool RestartJob(
int jobID);
187 static bool StopJob(
int jobID);
188 static bool DeleteJob(
int jobID);
189 static bool SafeDeleteJob(
int jobID,
int jobType,
int chanid,
190 const QDateTime& recstartts);
196 const QDateTime &recstartts);
197 static QString GetJobArgs(
int jobID);
198 static int UserJobTypeToIndex(
int JobType);
200 static bool DeleteAllJobs(
uint chanid,
const QDateTime &recstartts);
202 static void ClearJobMask(
int &mask) { mask =
JOB_NONE; }
203 static bool JobIsInMask(
int job,
int mask) {
return (
bool)(job & mask); }
204 static bool JobIsNotInMask(
int job,
int mask)
205 {
return ! JobIsInMask(job, mask); }
206 static void AddJobsToMask(
int jobs,
int &mask) { mask |= jobs; }
207 static void RemoveJobsFromMask(
int jobs,
int &mask) { mask &= ~jobs; }
209 static QString JobText(
int jobType);
210 static QString StatusText(
int status);
212 static bool HasRunningOrPendingJobs(std::chrono::minutes startingWithinMins = 0min);
214 static int GetJobsInQueue(QMap<int, JobQueueEntry> &jobs,
217 static void RecoverQueue(
bool justOld =
false);
218 static void RecoverOldJobsInQueue()
219 { RecoverQueue(
true); }
220 static void CleanupOldJobsInQueue();
222 static bool InJobRunWindow(QDateTime jobstarttsRaw);
231 void run(
void)
override;
232 void ProcessQueue(
void);
238 static bool InJobRunWindow(std::chrono::minutes orStartsWithinMins = 0min);
240 void StartChildJob(
void *(*ChildThreadRoutine)(
void *),
int jobID);
242 static QString GetJobDescription(
int jobType);
243 static QString GetJobCommand(
int id,
int jobType,
ProgramInfo *tmpInfo);
244 void RemoveRunningJob(
int id);
248 static void *TranscodeThread(
void *param);
249 void DoTranscodeThread(
int jobID);
251 static void *MetadataLookupThread(
void *param);
252 void DoMetadataLookupThread(
int jobID);
254 static void *FlagCommercialsThread(
void *param);
255 void DoFlagCommercialsThread(
int jobID);
257 static void *UserJobThread(
void *param);
258 void DoUserJobThread(
int jobID);
262 int m_jobsRunning {0};
263 int m_jobQueueCPU {0};
270 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
271 QMutex *m_runningJobsLock {
nullptr};
273 QRecursiveMutex *m_runningJobsLock {
nullptr};
275 QMap<int, RunningJobInfo> m_runningJobs;
280 QWaitCondition m_queueThreadCond;
281 QMutex m_queueThreadCondLock;
282 bool m_processQueue {
false};