Skip to content

Commit

Permalink
ENH: Stream DCMTK logging per each job to the job list UI
Browse files Browse the repository at this point in the history
This enhancement streams the DCMTK logging for each individual job directly to the Job List User Interface.
This improves visibility and accessibility of log information for each job, aiding in debugging and monitoring job performance.
  • Loading branch information
Punzo committed May 23, 2024
1 parent f86fe4d commit e689810
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 107 deletions.
41 changes: 35 additions & 6 deletions Libs/Core/ctkAbstractJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ ctkAbstractJob::~ctkAbstractJob()
{
}

//----------------------------------------------------------------------------
void ctkAbstractJob::setJobUID(const QString &jobUID)
{
this->JobUID = jobUID;
}

//----------------------------------------------------------------------------
QString ctkAbstractJob::className() const
{
Expand All @@ -67,6 +61,12 @@ QString ctkAbstractJob::jobUID() const
return this->JobUID;
}

//----------------------------------------------------------------------------
void ctkAbstractJob::setJobUID(const QString &jobUID)
{
this->JobUID = jobUID;
}

//----------------------------------------------------------------------------
ctkAbstractJob::JobStatus ctkAbstractJob::status() const
{
Expand Down Expand Up @@ -199,6 +199,35 @@ QDateTime ctkAbstractJob::completionDateTime() const
return this->CompletionDateTime;
}

//----------------------------------------------------------------------------
QString ctkAbstractJob::runningThreadID() const
{
return this->RunningThreadID;
}

//----------------------------------------------------------------------------
void ctkAbstractJob::setRunningThreadID(QString runningThreadID)
{
this->RunningThreadID = runningThreadID;
}

//----------------------------------------------------------------------------
QString ctkAbstractJob::loggedText() const
{
return this->LoggedText;
}

//----------------------------------------------------------------------------
void ctkAbstractJob::setLoggedText(QString loggedText)
{
if (loggedText.isEmpty())
{
return;
}

this->LoggedText += loggedText;
}

//----------------------------------------------------------------------------
QVariant ctkAbstractJob::toVariant()
{
Expand Down
26 changes: 23 additions & 3 deletions Libs/Core/ctkAbstractJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CTK_CORE_EXPORT ctkAbstractJob : public QObject
Q_PROPERTY(QDateTime creationDateTime READ creationDateTime);
Q_PROPERTY(QDateTime startDateTime READ startDateTime);
Q_PROPERTY(QDateTime completionDateTime READ completionDateTime);
Q_PROPERTY(QString runningThreadID READ runningThreadID WRITE setRunningThreadID);
Q_PROPERTY(QString loggedText READ loggedText WRITE setLoggedText);

public:
explicit ctkAbstractJob();
Expand Down Expand Up @@ -133,20 +135,32 @@ class CTK_CORE_EXPORT ctkAbstractJob : public QObject
///@}

///@{
/// CreationDateTime
/// Creation Date Time
QDateTime creationDateTime() const;
///@}

///@{
/// StartDateTime
/// Start Date Time
QDateTime startDateTime() const;
///@}

///@{
/// CompletionDateTime
/// Completion Date Time
QDateTime completionDateTime() const;
///@}

///@{
/// Running ThreadID
QString runningThreadID() const;
void setRunningThreadID(QString runningThreadID);
///@}

///@{
/// Logged Text
QString loggedText() const;
void setLoggedText(QString loggedText);
///@}

/// Generate worker for job
Q_INVOKABLE virtual ctkAbstractWorker* createWorker() = 0;

Expand Down Expand Up @@ -182,6 +196,8 @@ class CTK_CORE_EXPORT ctkAbstractJob : public QObject
QDateTime CreationDateTime;
QDateTime StartDateTime;
QDateTime CompletionDateTime;
QString RunningThreadID;
QString LoggedText;

private:
Q_DISABLE_COPY(ctkAbstractJob)
Expand All @@ -198,6 +214,8 @@ struct CTK_CORE_EXPORT ctkJobDetail {
this->CreationDateTime = job.creationDateTime().toString("HH:mm:ss.zzz ddd dd MMM yyyy");
this->StartDateTime = job.startDateTime().toString("HH:mm:ss.zzz ddd dd MMM yyyy");
this->CompletionDateTime = job.completionDateTime().toString("HH:mm:ss.zzz ddd dd MMM yyyy");
this->RunningThreadID = job.runningThreadID();
this->Logging = job.loggedText();
}
virtual ~ctkJobDetail() = default;

Expand All @@ -206,6 +224,8 @@ struct CTK_CORE_EXPORT ctkJobDetail {
QString CreationDateTime;
QString StartDateTime;
QString CompletionDateTime;
QString RunningThreadID;
QString Logging;
};
Q_DECLARE_METATYPE(ctkJobDetail);

Expand Down
14 changes: 6 additions & 8 deletions Libs/Core/ctkJobScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ctkJobSchedulerPrivate;
class CTK_CORE_EXPORT ctkJobScheduler : public QObject
{
Q_OBJECT
Q_PROPERTY(int numberOfJobs READ numberOfJobs);
Q_PROPERTY(int numberOfPersistentJobs READ numberOfPersistentJobs);
Q_PROPERTY(int numberOfRunningJobs READ numberOfRunningJobs);
Q_PROPERTY(int freezeJobsScheduling READ freezeJobsScheduling WRITE setFreezeJobsScheduling);
Q_PROPERTY(int maximumThreadCount READ maximumThreadCount WRITE setMaximumThreadCount);
Q_PROPERTY(int maximumNumberOfRetry READ maximumNumberOfRetry WRITE setMaximumNumberOfRetry);
Expand All @@ -52,22 +55,17 @@ class CTK_CORE_EXPORT ctkJobScheduler : public QObject

///@{
/// Jobs managment
Q_INVOKABLE int numberOfJobs();
Q_INVOKABLE int numberOfPersistentJobs();
Q_INVOKABLE int numberOfRunningJobs();

int numberOfJobs();
int numberOfPersistentJobs();
int numberOfRunningJobs();
Q_INVOKABLE void addJob(ctkAbstractJob* job);

Q_INVOKABLE virtual void deleteJob(const QString& jobUID);
Q_INVOKABLE virtual void deleteWorker(const QString& jobUID);

QSharedPointer<ctkAbstractJob> getJobSharedByUID(const QString& jobUID);
Q_INVOKABLE ctkAbstractJob* getJobByUID(const QString& jobUID);

Q_INVOKABLE void waitForFinish(bool waitForPersistentJobs = false,
bool processEvents = false);
Q_INVOKABLE void waitForDone(int msec = -1);

Q_INVOKABLE void stopAllJobs(bool stopPersistentJobs = false);
Q_INVOKABLE void stopJobsByJobUIDs(const QStringList& jobUIDs);
///@}
Expand Down
2 changes: 0 additions & 2 deletions Libs/DICOM/Core/Testing/Cpp/ctkDICOMSchedulerTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ int ctkDICOMSchedulerTest1(int argc, char* argv[])
QStringList urls = database.urlsForSeries(seriesIstanceUID);
urls.removeAll(QString(""));



CHECK_INT(instances.count(), numberOfImages);
CHECK_INT(files.count(), 0);
CHECK_INT(urls.count(), numberOfImages);
Expand Down
6 changes: 6 additions & 0 deletions Libs/DICOM/Core/ctkDICOMInserterWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "ctkDICOMInserterWorker_p.h"
#include "ctkDICOMJobResponseSet.h"

// DCMTK includes
#include <dcmtk/oflog/spi/logevent.h>

static ctkLogger logger ("org.commontk.dicom.DICOMInserterWorker");

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -100,6 +103,9 @@ void ctkDICOMInserterWorker::run()
return;
}

QString currentThread = dcmtk::log4cplus::thread::getCurrentThreadName().c_str();
inserterJob->setRunningThreadID(currentThread);

if (d->Inserter->wasCanceled())
{
this->onJobCanceled(d->Inserter->wasCanceled());
Expand Down
1 change: 0 additions & 1 deletion Libs/DICOM/Core/ctkDICOMJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ struct CTK_DICOM_CORE_EXPORT ctkDICOMJobDetail : ctkJobDetail

explicit ctkDICOMJobDetail(const ctkDICOMJob& job) : ctkJobDetail(job)
{

this->DICOMLevel = job.dicomLevel();
this->JobType = job.getJobType();
this->PatientID = job.patientID();
Expand Down
1 change: 1 addition & 0 deletions Libs/DICOM/Core/ctkDICOMJobResponseSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ctkDICOMJobResponseSetPrivate : public QObject
QString SeriesInstanceUID;
QString SOPInstanceUID;
QString ConnectionName;
QString RunningThreadID;
QMap<QString, QSharedPointer<ctkDICOMItem>> Datasets;
};

Expand Down
6 changes: 6 additions & 0 deletions Libs/DICOM/Core/ctkDICOMQueryWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "ctkDICOMScheduler.h"
#include "ctkDICOMServer.h"

// DCMTK includes
#include <dcmtk/oflog/spi/logevent.h>

static ctkLogger logger ("org.commontk.dicom.DICOMQueryWorker");

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -109,6 +112,9 @@ void ctkDICOMQueryWorker::run()
return;
}

QString currentThread = dcmtk::log4cplus::thread::getCurrentThreadName().c_str();
queryJob->setRunningThreadID(currentThread);

QSharedPointer<ctkDICOMScheduler> scheduler =
qobject_cast<QSharedPointer<ctkDICOMScheduler>>(this->Scheduler);
if (!scheduler ||
Expand Down
6 changes: 6 additions & 0 deletions Libs/DICOM/Core/ctkDICOMRetrieveWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "ctkDICOMScheduler.h"
#include "ctkDICOMServer.h"

// DCMTK includes
#include <dcmtk/oflog/spi/logevent.h>

static ctkLogger logger ("org.commontk.dicom.DICOMRetrieveWorker");

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -129,6 +132,9 @@ void ctkDICOMRetrieveWorker::run()
return;
}

QString currentThread = dcmtk::log4cplus::thread::getCurrentThreadName().c_str();
retrieveJob->setRunningThreadID(currentThread);

QSharedPointer<ctkDICOMScheduler> scheduler =
qSharedPointerObjectCast<ctkDICOMScheduler>(this->Scheduler);
ctkDICOMServer* server = retrieveJob->server();
Expand Down
Loading

0 comments on commit e689810

Please sign in to comment.