Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next round of ENHs for visual DICOM browser #1206

Merged
merged 16 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 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 All @@ -91,9 +91,13 @@ void ctkAbstractJob::setStatus(JobStatus status)
{
emit this->started();
}
else if (this->Status == JobStatus::Stopped)
else if (this->Status == JobStatus::UserStopped)
{
emit this->userStopped();
}
else if (this->Status == JobStatus::AttemptFailed)
{
emit this->canceled();
emit this->attemptFailed();
}
else if (this->Status == JobStatus::Failed)
{
Expand Down Expand Up @@ -195,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
39 changes: 32 additions & 7 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 All @@ -71,16 +73,20 @@ class CTK_CORE_EXPORT ctkAbstractJob : public QObject
///@{
/// Status
/// Initialized: the object has been created and inserted in the JobsQueue map in the ctkJobScheduler
/// Queued: a worker is associated to the job and the worker has been inserted in the queue list of the QThreadPool (object owned by the ctkJobScheduler) with a priority
/// Queued: a worker is associated to the job and the worker has been inserted in the queue list of
/// the QThreadPool (object owned by the ctkJobScheduler) with a priority
/// Running: the job is running in another thread by the associated worker.
/// Stopped: the job has been stopped externally (a cancel request from the worker)
/// UserStopped: the job has been stopped externally (a cancel request from the worker)
/// AttemptFailed: the job encountered an internal failure, however, the task will be reattempted
/// by a different job (as the logic returned false).
/// Failed: the job failed internally (logic returns false).
/// Finished: the job has been run successfully (logic returns true).
enum JobStatus {
Initialized = 0,
Queued,
Running,
Stopped,
UserStopped,
AttemptFailed,
Failed,
Finished,
};
Expand Down Expand Up @@ -129,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 All @@ -161,7 +179,8 @@ class CTK_CORE_EXPORT ctkAbstractJob : public QObject

Q_SIGNALS:
void started();
void canceled();
void userStopped();
void attemptFailed();
void failed();
void finished();

Expand All @@ -177,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 @@ -193,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 @@ -201,6 +224,8 @@ struct CTK_CORE_EXPORT ctkJobDetail {
QString CreationDateTime;
QString StartDateTime;
QString CompletionDateTime;
QString RunningThreadID;
QString Logging;
};
Q_DECLARE_METATYPE(ctkJobDetail);

Expand Down
8 changes: 6 additions & 2 deletions Libs/Core/ctkAbstractWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ void ctkAbstractWorker::onJobCanceled(const bool& wasCanceled)
timer.start(this->Job->retryDelay());

this->startNextJob();
this->Job->setStatus(ctkAbstractJob::JobStatus::AttemptFailed);
}
else
{
this->Job->setStatus(ctkAbstractJob::JobStatus::Failed);
}
this->Job->setStatus(ctkAbstractJob::JobStatus::Failed);
}
else
{
this->Job->setStatus(ctkAbstractJob::JobStatus::Stopped);
this->Job->setStatus(ctkAbstractJob::JobStatus::UserStopped);
}
}
Loading
Loading