Commit e0bbb0a0 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Ensure to cancel every expired or not added job

Previosly the JobQueue cancelled job requests for some reasons, but not
for others. Conceptually, JobQueue should not make any difference
between those.

Introduce equal treatment and always cancel if a job request could not
be added or is expired as this avoids leaving the Qt Creator side
waiting for a response.

Change-Id: I26b392b7f80b89ba2ae9a46a8d1b51403ec6eb4a
Reviewed-by: Ivan Donchevskii's avatarIvan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Marco Bubke's avatarMarco Bubke <marco.bubke@qt.io>
parent f8d15c39
...@@ -43,33 +43,16 @@ JobQueue::JobQueue(Documents &documents, ProjectParts &projectParts) ...@@ -43,33 +43,16 @@ JobQueue::JobQueue(Documents &documents, ProjectParts &projectParts)
bool JobQueue::add(const JobRequest &job) bool JobQueue::add(const JobRequest &job)
{ {
if (m_queue.contains(job)) { QString notAddableReason;
qCDebug(jobsLog) << "Not adding duplicate request" << job; if (isJobRequestAddable(job, notAddableReason)) {
return false; qCDebug(jobsLog) << "Adding" << job;
} m_queue.append(job);
return true;
if (isJobRunningForJobRequest(job)) { } else {
qCDebug(jobsLog) << "Not adding duplicate request for already running job" << job; qCDebug(jobsLog) << "Not adding" << job << notAddableReason;
return false;
}
if (!m_documents.hasDocument(job.filePath, job.projectPartId)) {
qCDebug(jobsLog) << "Not adding / cancelling due to already closed document:" << job;
cancelJobRequest(job);
return false;
}
const Document document = m_documents.document(job.filePath, job.projectPartId);
if (!document.isIntact()) {
qCDebug(jobsLog) << "Not adding / cancelling due not intact document:" << job;
cancelJobRequest(job); cancelJobRequest(job);
return false; return false;
} }
qCDebug(jobsLog) << "Adding" << job;
m_queue.append(job);
return true;
} }
int JobQueue::size() const int JobQueue::size() const
...@@ -92,8 +75,13 @@ void JobQueue::removeExpiredRequests() ...@@ -92,8 +75,13 @@ void JobQueue::removeExpiredRequests()
foreach (const JobRequest &jobRequest, m_queue) { foreach (const JobRequest &jobRequest, m_queue) {
try { try {
if (!isJobRequestExpired(jobRequest)) QString expirationReason;
if (isJobRequestExpired(jobRequest, expirationReason)) {
qCDebug(jobsLog) << "Expired:" << jobRequest << expirationReason;
cancelJobRequest(jobRequest);
} else {
cleanedRequests.append(jobRequest); cleanedRequests.append(jobRequest);
}
} catch (const std::exception &exception) { } catch (const std::exception &exception) {
qWarning() << "Error in Jobs::removeOutDatedRequests for" qWarning() << "Error in Jobs::removeOutDatedRequests for"
<< jobRequest << ":" << exception.what(); << jobRequest << ":" << exception.what();
...@@ -103,7 +91,33 @@ void JobQueue::removeExpiredRequests() ...@@ -103,7 +91,33 @@ void JobQueue::removeExpiredRequests()
m_queue = cleanedRequests; m_queue = cleanedRequests;
} }
bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest) bool JobQueue::isJobRequestAddable(const JobRequest &jobRequest, QString &notAddableReason)
{
if (m_queue.contains(jobRequest)) {
notAddableReason = "duplicate request in queue";
return false;
}
if (isJobRunningForJobRequest(jobRequest)) {
notAddableReason = "duplicate request for already running job";
return false;
}
if (!m_documents.hasDocument(jobRequest.filePath, jobRequest.projectPartId)) {
notAddableReason = "document already closed";
return false;
}
const Document document = m_documents.document(jobRequest.filePath, jobRequest.projectPartId);
if (!document.isIntact()) {
notAddableReason = "document not intact";
return false;
}
return true;
}
bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest, QString &expirationReason)
{ {
const JobRequest::ExpirationConditions conditions = jobRequest.expirationConditions; const JobRequest::ExpirationConditions conditions = jobRequest.expirationConditions;
const UnsavedFiles unsavedFiles = m_documents.unsavedFiles(); const UnsavedFiles unsavedFiles = m_documents.unsavedFiles();
...@@ -111,7 +125,7 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest) ...@@ -111,7 +125,7 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest)
if (conditions.testFlag(Condition::UnsavedFilesChanged)) { if (conditions.testFlag(Condition::UnsavedFilesChanged)) {
if (jobRequest.unsavedFilesChangeTimePoint != unsavedFiles.lastChangeTimePoint()) { if (jobRequest.unsavedFilesChangeTimePoint != unsavedFiles.lastChangeTimePoint()) {
qCDebug(jobsLog) << "Removing due to outdated unsaved files:" << jobRequest; expirationReason = "outdated unsaved files";
return true; return true;
} }
} }
...@@ -120,12 +134,12 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest) ...@@ -120,12 +134,12 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest)
if (conditions.testFlag(Condition::DocumentClosed)) { if (conditions.testFlag(Condition::DocumentClosed)) {
if (!m_documents.hasDocument(jobRequest.filePath, jobRequest.projectPartId)) { if (!m_documents.hasDocument(jobRequest.filePath, jobRequest.projectPartId)) {
qCDebug(jobsLog) << "Removing due to already closed document:" << jobRequest; expirationReason = "document already closed";
return true; return true;
} }
if (!m_projectParts.hasProjectPart(jobRequest.projectPartId)) { if (!m_projectParts.hasProjectPart(jobRequest.projectPartId)) {
qCDebug(jobsLog) << "Removing due to already closed project:" << jobRequest; expirationReason = "project already closed";
return true; return true;
} }
projectCheckedAndItExists = true; projectCheckedAndItExists = true;
...@@ -133,14 +147,13 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest) ...@@ -133,14 +147,13 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest)
const Document document const Document document
= m_documents.document(jobRequest.filePath, jobRequest.projectPartId); = m_documents.document(jobRequest.filePath, jobRequest.projectPartId);
if (!document.isIntact()) { if (!document.isIntact()) {
qCDebug(jobsLog) << "Removing/Cancelling due to not intact document:" << jobRequest; expirationReason = "document not intact";
cancelJobRequest(jobRequest);
return true; return true;
} }
if (conditions.testFlag(Condition::DocumentRevisionChanged)) { if (conditions.testFlag(Condition::DocumentRevisionChanged)) {
if (document.documentRevision() > jobRequest.documentRevision) { if (document.documentRevision() > jobRequest.documentRevision) {
qCDebug(jobsLog) << "Removing due to changed document revision:" << jobRequest; expirationReason = "changed document revision";
return true; return true;
} }
} }
...@@ -148,13 +161,13 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest) ...@@ -148,13 +161,13 @@ bool JobQueue::isJobRequestExpired(const JobRequest &jobRequest)
if (conditions.testFlag(Condition::ProjectChanged)) { if (conditions.testFlag(Condition::ProjectChanged)) {
if (!projectCheckedAndItExists && !m_projectParts.hasProjectPart(jobRequest.projectPartId)) { if (!projectCheckedAndItExists && !m_projectParts.hasProjectPart(jobRequest.projectPartId)) {
qCDebug(jobsLog) << "Removing due to already closed project:" << jobRequest; expirationReason = "project already closed";
return true; return true;
} }
const ProjectPart &project = m_projectParts.project(jobRequest.projectPartId); const ProjectPart &project = m_projectParts.project(jobRequest.projectPartId);
if (project.lastChangeTimePoint() != jobRequest.projectChangeTimePoint) { if (project.lastChangeTimePoint() != jobRequest.projectChangeTimePoint) {
qCDebug(jobsLog) << "Removing due to outdated project:" << jobRequest; expirationReason = "outdated project";
return true; return true;
} }
} }
......
...@@ -66,7 +66,8 @@ private: ...@@ -66,7 +66,8 @@ private:
bool isJobRunningForJobRequest(const JobRequest &jobRequest); bool isJobRunningForJobRequest(const JobRequest &jobRequest);
JobRequests takeJobRequestsToRunNow(); JobRequests takeJobRequestsToRunNow();
void removeExpiredRequests(); void removeExpiredRequests();
bool isJobRequestExpired(const JobRequest &jobRequest); bool isJobRequestAddable(const JobRequest &jobRequest, QString &notAddableReason);
bool isJobRequestExpired(const JobRequest &jobRequest, QString &expirationReason);
private: private:
Documents &m_documents; Documents &m_documents;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment