Commit d7a6c808 authored by John Tourtellott's avatar John Tourtellott
Browse files

Add qtCumulusJobTracker::addNewJob() for immediate fetch

* And fixes bug that inserted 2 rows into QModel instead of 1
* Note that queueJobId not always set by first request
* Also disable polling in the old jobs panel by default
parent 8b324dbf
......@@ -96,7 +96,7 @@ pqCumulusJobsPanel::pqCumulusJobsPanel(QWidget* parent)
optionsLayout->addWidget(this->Internal->AuthenticateButton, 0, Qt::AlignHCenter);
this->Internal->PollingCheckbox = new QCheckBox("Polling");
this->Internal->PollingCheckbox->setCheckState(Qt::Checked);
this->Internal->PollingCheckbox->setCheckState(Qt::Unchecked);
this->Internal->PollingCheckbox->setEnabled(loggedIn);
optionsLayout->addWidget(this->Internal->PollingCheckbox, 0, Qt::AlignRight);
......
......@@ -117,6 +117,12 @@ void qtCumulusJobTracker::addJob(const QString& cumulusJobId, bool checkUnique)
this->setNextPoll();
}
void qtCumulusJobTracker::addNewJob(const QString& cumulusJobId)
{
m_internal->m_jobList.push_back(cumulusJobId);
this->setNextPoll(true);
}
void qtCumulusJobTracker::clear()
{
bool wasPolling = this->isPolling();
......@@ -243,10 +249,13 @@ void qtCumulusJobTracker::onCumulusReply()
{
jResponse = nlohmann::json::parse(bytes.constData());
}
catch (...)
catch (std::exception const & ex)
{
qWarning() << __FILE__ << __LINE__ << ":" << networkReply->errorString();
emit error(networkReply->errorString());
QString errMessage;
QTextStream qs(&errMessage);
qs << "Error parsing cumulus reply: " << bytes.constData();
qWarning() << __FILE__ << __LINE__ << errMessage;
emit error(errMessage);
networkReply->deleteLater();
return;
}
......@@ -268,6 +277,10 @@ void qtCumulusJobTracker::onCumulusReply()
{
errorMessage = QString(bytes);
}
else if (jResponse["message"].is_null())
{
errorMessage = QString(bytes);
}
else
{
std::string message = jResponse["message"].get<std::string>();
......@@ -288,10 +301,37 @@ void qtCumulusJobTracker::onCumulusReply()
else
{
QString cumulusJobId(jResponse["_id"].get<std::string>().c_str());
QString status(jResponse["status"].get<std::string>().c_str());
QString queueJobId(jResponse["queueJobId"].get<std::string>().c_str());
emit this->jobStatus(cumulusJobId, status, queueJobId);
// Get fields from jResponse
QString cumulusJobId;
QString status;
QString queueJobId;
nlohmann::json::iterator iter;
iter = jResponse.find("status");
if (iter != jResponse.end())
{
status = (*iter).get<std::string>().c_str();
}
iter = jResponse.find("queueJobId");
if (iter != jResponse.end())
{
queueJobId = (*iter).get<std::string>().c_str();
}
iter = jResponse.find("_id");
if (iter == jResponse.end())
{
QString errMessage;
QTextStream qs(&errMessage);
qs << "Cumulus response missing _id: " << bytes.constData();
qWarning() << errMessage;
}
else
{
cumulusJobId = (*iter).get<std::string>().c_str();
emit this->jobStatus(cumulusJobId, status, queueJobId);
}
// Check if job status is a final state, remove from the list.
if ((status == "complete") || (status == "error"))
......@@ -370,7 +410,8 @@ bool qtCumulusJobTracker::setNextPoll(bool pollNow)
if (pollNow)
{
m_internal->m_timer->start(0);
// Use 1000 msec to give time for queue id to be assigned
QTimer::singleShot(1000, this, &qtCumulusJobTracker::onTimerEvent);
}
else
{
......
......@@ -42,7 +42,14 @@ public:
qtCumulusJobTracker(QObject* parent = nullptr);
~qtCumulusJobTracker() override;
// For adding jobs when first loading project, e.g.
void addJob(const QString& cumulusJobId, bool checkUnique = true);
// For adding newly-created job
// * does NOT check is job already in the list
// * polls cumulus immediately then starts regular interval
void addNewJob(const QString& cumulusJobId);
void clear();
// Return value indicates whether polling is on/off
......
......@@ -232,6 +232,7 @@ void qtJobsModel::onJobStatus(const QString& cumulusJobId, const QString& status
if (changed)
{
// Mark project as modified
// Future: write job manifest file
m_project->setClean(false);
// For now, signal that entire row changed
......@@ -266,10 +267,10 @@ void qtJobsModel::onJobAdded(const QString& cumulusJobId)
// Add row to model
int row = static_cast<int>(index);
this->beginInsertRows(QModelIndex(), row, row + 1);
this->beginInsertRows(QModelIndex(), row, row);
this->endInsertRows();
m_jobTracker->addJob(cumulusJobId);
m_jobTracker->addNewJob(cumulusJobId);
}
void qtJobsModel::initTrackerJobList()
......
Supports Markdown
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