Skip to content

Commit

Permalink
Add 'timeout' option for commands (fix #2671)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Apr 30, 2022
1 parent 95ec90a commit 28d1471
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/gui/src/settings/options-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ OptionsWindow::OptionsWindow(Profile *profile, ThemeLoader *themeLoader, QWidget
ui->lineCommandsImage->setText(settings->value("image").toString());
ui->lineCommandsTagAfter->setText(settings->value("tag_after", settings->value("tag").toString()).toString());
ui->checkCommandsDryRun->setChecked(settings->value("dry_run", false).toBool());
ui->spinCommandsTimeout->setValue(settings->value("timeout", 30).toInt());
settings->beginGroup("SQL");
ui->comboCommandsSqlDriver->addItems(QSqlDatabase::drivers());
ui->comboCommandsSqlDriver->setCurrentIndex(QSqlDatabase::drivers().indexOf(settings->value("driver", "QMYSQL").toString()));
Expand Down Expand Up @@ -1366,6 +1367,7 @@ void OptionsWindow::save()
settings->setValue("image", ui->lineCommandsImage->text());
settings->setValue("tag_after", ui->lineCommandsTagAfter->text());
settings->setValue("dry_run", ui->checkCommandsDryRun->isChecked());
settings->setValue("timeout", ui->spinCommandsTimeout->value());
settings->beginGroup("SQL");
settings->setValue("driver", ui->comboCommandsSqlDriver->currentText());
settings->setValue("host", ui->lineCommandsSqlHost->text());
Expand Down
54 changes: 37 additions & 17 deletions src/gui/src/settings/options-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
<normaloff>:/images/icon.ico</normaloff>:/images/icon.ico</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
Expand Down Expand Up @@ -1139,8 +1129,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<height>505</height>
<width>57</width>
<height>16</height>
</rect>
</property>
<layout class="QVBoxLayout" name="scrollAreaWidgetLayout">
Expand Down Expand Up @@ -1813,7 +1803,7 @@
<x>0</x>
<y>0</y>
<width>323</width>
<height>407</height>
<height>462</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -3901,7 +3891,7 @@
<x>0</x>
<y>0</y>
<width>235</width>
<height>785</height>
<height>840</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
Expand Down Expand Up @@ -5159,9 +5149,6 @@
</widget>
<widget class="QWidget" name="pageCommands">
<layout class="QFormLayout" name="formLayout_18">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_36">
<property name="text">
Expand Down Expand Up @@ -5202,6 +5189,29 @@
<item row="3" column="1">
<widget class="QLineEdit" name="lineCommandsTagAfter"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Timeout</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinCommandsTimeout">
<property name="suffix">
<string> s</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>3600</number>
</property>
<property name="value">
<number>30</number>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="checkCommandsDryRun">
<property name="text">
Expand Down Expand Up @@ -5353,6 +5363,16 @@
</widget>
</widget>
</item>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/src/commands/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Commands::Commands(Profile *profile)
{
QSettings *settings = profile->getSettings();

m_timeout = settings->value("Exec/timeout", 30).toInt() * 1000;
m_dryRun = settings->value("Exec/dry_run", false).toBool();
m_commandTagBefore = settings->value("Exec/tag_before").toString();
m_commandImage = settings->value("Exec/image").toString();
Expand Down Expand Up @@ -169,8 +170,8 @@ bool Commands::execute(const QString &command) const
QObject::connect(&proc, &QProcess::readyReadStandardOutput, [&proc]() { log(QStringLiteral("[Command stdout] %1").arg(QString(proc.readAllStandardOutput())), Logger::Debug); });
QObject::connect(&proc, &QProcess::readyReadStandardError, [&proc]() { log(QStringLiteral("[Command stderr] %1").arg(QString(proc.readAllStandardError())), Logger::Error); });

// Wait for the command to finish 30s
if (!proc.waitForFinished()) {
// Wait for the command to finish
if (!proc.waitForFinished(m_timeout)) {
log(QStringLiteral("Command execution timeout"), Logger::Error);
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/src/commands/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Commands
private:
Profile *m_profile;

int m_timeout; // milliseconds
bool m_dryRun;
QString m_commandTagBefore;
QString m_commandImage;
Expand Down

0 comments on commit 28d1471

Please sign in to comment.