16 #include "Device/Histo/SimulationResult.h"
23 #include "Sim/Simulation/ISimulation.h"
27 : m_jobModel(jobModel)
45 throw Error(
"JobQueueData::runJob() -> Error. ISimulation is already existing.");
51 }
catch (
const std::exception& ex) {
52 QString message(
"JobQueueData::runJob() -> Error. "
53 "Attempt to create sample/instrument object from user description "
54 "has failed with following error message.\n\n");
55 message += QString::fromStdString(std::string(ex.what()));
66 auto* thread =
new QThread;
67 worker->moveToThread(thread);
106 auto* worker = qobject_cast<JobWorker*>(sender());
111 jobItem->setBeginTime(worker->simulationStart());
112 jobItem->setEndTime(QDateTime());
119 auto* worker = qobject_cast<JobWorker*>(sender());
139 auto* thread = qobject_cast<QThread*>(sender());
145 auto* worker = qobject_cast<JobWorker*>(sender());
156 int global_progress(0);
159 if (jobItem->isRunning()) {
160 global_progress += jobItem->getProgress();
165 global_progress /= nRunningJobs;
167 global_progress = -1;
185 if (it.value() == thread) {
186 thread->deleteLater();
192 throw Error(
"JobQueueData::assignForDeletion() -> Error! Can't find thread.");
200 worker->disconnect();
202 if (it.value() == worker) {
209 throw Error(
"JobQueueData::assignForDeletion() -> Error! Can't find the runner.");
244 return it !=
m_threads.end() ? it.value() :
nullptr;
252 return it !=
m_workers.end() ? it.value() :
nullptr;
Defines class JobQueueData.
@ Running
the job is busy calculating
@ Failed
the job aborted because it hit an error
Defines class Helpers functions.
Defines namespace GUI::Transform::ToCore.
void setComments(const QString &comments)
void setEndTime(const QDateTime &end_time)
const SimulationOptionsItem & simulationOptionsItem() const
void setStatus(JobStatus status)
void setResults(const SimulationResult &result)
MultiLayerItem * sampleItem()
void setProgress(int progress)
InstrumentItem * instrumentItem() const
QString getIdentifier() const
QVector< JobItem * > jobItems() const
JobItem * getJobItemForIdentifier(const QString &identifier)
JobWorker * getWorker(const QString &identifier)
Returns job runner for given identifier.
void onStartedJob()
Sets JobItem properties when the job is going to start.
void focusRequest(JobItem *jobItem)
void updateGlobalProgress()
Estimates global progress from the progress of multiple running jobs and emits appropriate signal.
QThread * getThread(const QString &identifier)
Returns the thread for given identifier.
JobQueueData(JobModel *jobModel)
ISimulation * getSimulation(const QString &identifier)
Returns the simulation (if exists) for given identifier.
void removeJob(const QString &identifier)
Remove job from list completely.
void processFinishedJob(JobWorker *worker, JobItem *jobItem)
Set all data of finished job.
void cancelJob(const QString &identifier)
Cancels running job.
QMap< QString, ISimulation * > m_simulations
job identifier to jobWorker
void clearSimulation(const QString &identifier)
void onFinishedJob()
Performs necessary actions when job is finished.
void assignForDeletion(QThread *thread)
Removes QThread from the map of known threads, assigns it for deletion.
JobModel * m_jobModel
job identifier to simulation
QMap< QString, JobWorker * > m_workers
job identifier to the thread
QMap< QString, QThread * > m_threads
void runJob(JobItem *jobItem)
Submits job and run it in a thread.
void onCancelAllJobs()
Cancels all running jobs.
The JobWorker class provides running the domain simulation in a thread.
QString failureMessage() const
const SimulationResult * result() const
const QDateTime & simulationEnd() const
void terminate()
Sets request for JobRunner to terminate underlying domain simulation.