mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
improve settings and limits
This commit is contained in:
parent
84b8632ae8
commit
bd62bc8777
@ -31,6 +31,7 @@
|
||||
#include "QueuedCoreInterface.h"
|
||||
#include "QueuedCorePropertiesInterface.h"
|
||||
#include "QueuedDatabase.h"
|
||||
#include "QueuedDatabaseManager.h"
|
||||
#include "QueuedDebug.h"
|
||||
#include "QueuedEnums.h"
|
||||
#include "QueuedExceptions.h"
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
#include "QueuedConfiguration.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief implementation over database stored settings
|
||||
@ -53,6 +55,13 @@ public:
|
||||
* @return value by key if found
|
||||
*/
|
||||
QVariant get(const QString &_key) const;
|
||||
/**
|
||||
* @brief get value
|
||||
* @param _key
|
||||
* key to search in
|
||||
* @return value by key if found
|
||||
*/
|
||||
QVariant get(const QueuedCfg::QueuedSettings _key) const;
|
||||
/**
|
||||
* @brief get database value ID
|
||||
* @param _key
|
||||
@ -60,6 +69,13 @@ public:
|
||||
* @return database id or -1 if not found
|
||||
*/
|
||||
long long id(const QString &_key) const;
|
||||
/**
|
||||
* @brief get internal ID by given string key
|
||||
* @param _key
|
||||
* string key
|
||||
* @return ID in settings representation
|
||||
*/
|
||||
static QString internalId(const QString &_key);
|
||||
/**
|
||||
* @brief set value
|
||||
* @param _key
|
||||
@ -83,7 +99,8 @@ signals:
|
||||
* @param _value
|
||||
* changed value
|
||||
*/
|
||||
void valueUpdated(const QString &_key, const QVariant &_value);
|
||||
void valueUpdated(const QueuedCfg::QueuedSettings _key,
|
||||
const QVariant &_value);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -24,7 +24,9 @@
|
||||
#ifndef QUEUEDCONFIGURATION_H
|
||||
#define QUEUEDCONFIGURATION_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
/**
|
||||
@ -47,7 +49,7 @@ typedef struct {
|
||||
QString password;
|
||||
} QueuedAdminSetup;
|
||||
/**
|
||||
* m@ingroup QueuedCfg
|
||||
* @ingroup QueuedCfg
|
||||
* @struct QueuedDBSetup
|
||||
* @brief structure to define database setup
|
||||
* @var driver
|
||||
@ -71,7 +73,67 @@ typedef struct {
|
||||
int port;
|
||||
QString username;
|
||||
} QueuedDBSetup;
|
||||
/**
|
||||
* @ingroup QueuedCfg
|
||||
* @enum Settings
|
||||
* @brief settings keys enum
|
||||
* @var Settigns::Invalid
|
||||
* unknown key
|
||||
* @var Settings::DatabaseInterval
|
||||
* database actions interval in msecs
|
||||
* @var Settings::DefaultLimits
|
||||
* default limits value
|
||||
* @var Settings::KeepTasks
|
||||
* keep ended tasks in msecs
|
||||
* @var Settings::KeepUsers
|
||||
* keep users last logged in msecs
|
||||
* @var Settings::OnExitAction
|
||||
* on queued exit action enum
|
||||
* @var Settings::TokenExpiration
|
||||
* token expiration value in days
|
||||
*/
|
||||
enum class QueuedSettings {
|
||||
Invalid = 1 << 0,
|
||||
DatabaseInterval = 1 << 1,
|
||||
DefaultLimits = 1 << 2,
|
||||
KeepTasks = 1 << 3,
|
||||
KeepUsers = 1 << 4,
|
||||
OnExitAction = 1 << 5,
|
||||
TokenExpiration = 1 << 6,
|
||||
};
|
||||
/**
|
||||
* @ingroup QueuedCfg
|
||||
* @struct QueuedSettingsField
|
||||
* @brief structure to define advanced settings field
|
||||
* @var id
|
||||
* interval field ID
|
||||
* @var key
|
||||
* settings key
|
||||
* @var defaultValue
|
||||
* settings default value
|
||||
*/
|
||||
typedef struct {
|
||||
QueuedSettings id;
|
||||
QVariant defaultValue;
|
||||
} QueuedSettingsField;
|
||||
/**
|
||||
* @ingroup QueuedCfg
|
||||
* @typedef QueuedProcessConnectionMap
|
||||
* map of settings indices to related values
|
||||
*/
|
||||
typedef QHash<QString, QueuedSettingsField> QueuedSettingsDefaultMap;
|
||||
/**
|
||||
* @ingroup QueuedCfg
|
||||
* @brief default settings map
|
||||
*/
|
||||
const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
||||
{"", {QueuedSettings::Invalid, QVariant()}},
|
||||
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}},
|
||||
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\x010\x010\x010\x010"}},
|
||||
{"KeepTasks", {QueuedSettings::KeepTasks, 0}},
|
||||
{"KeepUsers", {QueuedSettings::KeepUsers, 0}},
|
||||
{"OnExitAction", {QueuedSettings::OnExitAction, 2}},
|
||||
{"TokenExpiration", {QueuedSettings::TokenExpiration, 39}}};
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDCONFIGURATION_H */
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "QueuedConfiguration.h"
|
||||
#include "QueuedEnums.h"
|
||||
#include "QueuedLimits.h"
|
||||
#include "QueuedUserManager.h"
|
||||
@ -33,6 +34,7 @@
|
||||
|
||||
class QueuedAdvancedSettings;
|
||||
class QueuedDatabase;
|
||||
class QueuedDatabaseManager;
|
||||
class QueuedProcess;
|
||||
class QueuedProcessManager;
|
||||
class QueuedReportManager;
|
||||
@ -166,6 +168,13 @@ public:
|
||||
const QueuedEnums::Permission &_permission,
|
||||
const bool _add,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
/**
|
||||
* @brief get value from advanced settings
|
||||
* @param _key
|
||||
* key string
|
||||
* @return option value or empty QVariant
|
||||
*/
|
||||
QVariant option(const QString &_key);
|
||||
/**
|
||||
* @brief force start task
|
||||
* @param _id
|
||||
@ -222,7 +231,8 @@ private slots:
|
||||
* @param _value
|
||||
* new value
|
||||
*/
|
||||
void updateSettings(const QString &_key, const QVariant &_value);
|
||||
void updateSettings(const QueuedCfg::QueuedSettings _key,
|
||||
const QVariant &_value);
|
||||
/**
|
||||
* @brief update process time
|
||||
* @param _id
|
||||
@ -252,6 +262,10 @@ private:
|
||||
* @brief pointer to database object
|
||||
*/
|
||||
QueuedDatabase *m_database = nullptr;
|
||||
/**
|
||||
* @brief pointer to database manager object
|
||||
*/
|
||||
QueuedDatabaseManager *m_databaseManager = nullptr;
|
||||
/**
|
||||
* @brief pointer to process manager
|
||||
*/
|
||||
|
@ -53,6 +53,13 @@ public:
|
||||
virtual ~QueuedCorePropertiesInterface();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief get advanced option
|
||||
* @param property
|
||||
* property name
|
||||
* @return property value or empty if property not found
|
||||
*/
|
||||
QDBusVariant Option(const QString &property);
|
||||
/**
|
||||
* @brief get task property
|
||||
* @param id
|
||||
|
130
sources/queued/include/queued/QueuedDatabaseManager.h
Normal file
130
sources/queued/include/queued/QueuedDatabaseManager.h
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
/**
|
||||
* @file QueuedDatabaseManager.h
|
||||
* Header of Queued library
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright MIT
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QUEUEDDATABASEMANAGER_H
|
||||
#define QUEUEDDATABASEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
class QueuedDatabase;
|
||||
|
||||
/**
|
||||
* @brief additional methods over database manager
|
||||
*/
|
||||
class QueuedDatabaseManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(long long interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(long long keepTasks READ keepTasks WRITE setKeepTasks)
|
||||
Q_PROPERTY(long long keepUsers READ keepUsers WRITE setKeepUsers)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief additional constant to store msecs in day count
|
||||
*/
|
||||
const long long MSEC_IN_DAY = 86400000;
|
||||
|
||||
/**
|
||||
* @brief QueuedDatabaseManager class constructor
|
||||
* @param parent
|
||||
* pointer to parent item
|
||||
* @param database
|
||||
* pointer to database object
|
||||
*/
|
||||
explicit QueuedDatabaseManager(QObject *parent, QueuedDatabase *database);
|
||||
/**
|
||||
* @brief QueuedDatabaseManager class destructor
|
||||
*/
|
||||
virtual ~QueuedDatabaseManager();
|
||||
/**
|
||||
* @brief start timer
|
||||
*/
|
||||
void startWorker();
|
||||
// properties
|
||||
/**
|
||||
* @breef database actions interval
|
||||
* @return interval in milliseconds
|
||||
*/
|
||||
long long interval() const;
|
||||
/**
|
||||
* @brief keep ended tasks
|
||||
* @return interval for keeping tasks in milliseconds
|
||||
*/
|
||||
long long keepTasks() const;
|
||||
/**
|
||||
* @brief keep users last logged in
|
||||
* @return interval for keeping users in milliseconds
|
||||
*/
|
||||
long long keepUsers() const;
|
||||
/**
|
||||
* @brief set database actions interval
|
||||
* @param _interval
|
||||
* interval in milliseconds
|
||||
*/
|
||||
void setInterval(const long long _interval);
|
||||
/**
|
||||
* @brief keep interval for tasks
|
||||
* @param _keepInterval
|
||||
* interval in milliseconds
|
||||
*/
|
||||
void setKeepTasks(const long long _keepInterval);
|
||||
/**
|
||||
* @brief keep interval for users
|
||||
* @param _keepInterval
|
||||
* interval in milliseconds
|
||||
*/
|
||||
void setKeepUsers(const long long _keepInterval);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief cleanup database
|
||||
*/
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief pointer to database object
|
||||
*/
|
||||
QueuedDatabase *m_database = nullptr;
|
||||
/**
|
||||
* @brief database actions interval
|
||||
*/
|
||||
long long m_interval = MSEC_IN_DAY;
|
||||
/**
|
||||
* @brief ended task interval
|
||||
*/
|
||||
long long m_keepTasks = 0;
|
||||
/**
|
||||
* @brief user last logged in interval
|
||||
*/
|
||||
long long m_keepUsers = 0;
|
||||
/**
|
||||
* @brief timer object
|
||||
*/
|
||||
QTimer m_timer;
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDDATABASEMANAGER_H */
|
@ -45,7 +45,8 @@ class QueuedProcess : public QProcess
|
||||
setCommandArguments)
|
||||
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime)
|
||||
Q_PROPERTY(uint gid READ uid WRITE setGid)
|
||||
Q_PROPERTY(QueuedLimits::Limits limits READ limits WRITE setLimits)
|
||||
Q_PROPERTY(QString limits READ limits WRITE setLimits)
|
||||
Q_PROPERTY(QueuedLimits::Limits nativeLimtis READ nativeLimits)
|
||||
Q_PROPERTY(uint nice READ nice WRITE setNice)
|
||||
Q_PROPERTY(QueuedEnums::ProcessState pstate READ pstate WRITE setPState)
|
||||
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime)
|
||||
@ -90,7 +91,7 @@ public:
|
||||
QDateTime startTime;
|
||||
QDateTime endTime;
|
||||
long long user;
|
||||
QueuedLimits::Limits limits;
|
||||
QString limits;
|
||||
QueuedEnums::ProcessState state;
|
||||
} QueuedProcessDefinitions;
|
||||
|
||||
@ -145,7 +146,12 @@ public:
|
||||
* @brief process limits
|
||||
* @return process defined limits
|
||||
*/
|
||||
QueuedLimits::Limits limits() const;
|
||||
QString limits() const;
|
||||
/**
|
||||
* @brief process limits
|
||||
* @return process defined limits in native format
|
||||
*/
|
||||
QueuedLimits::Limits nativeLimits() const;
|
||||
/**
|
||||
* @brief process nice
|
||||
* @return process nice
|
||||
@ -204,7 +210,7 @@ public:
|
||||
* @param _limits
|
||||
* new process limits
|
||||
*/
|
||||
void setLimits(const QueuedLimits::Limits &_limits);
|
||||
void setLimits(const QString &_limits);
|
||||
/**
|
||||
* @brief set process nice
|
||||
* @param _nice
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
* @var OnExitAction::Kill
|
||||
* send SIGKILL on exit
|
||||
*/
|
||||
enum class OnExitAction { Terminate, Kill };
|
||||
enum class OnExitAction { Terminate = 1 << 1, Kill = 1 << 2 };
|
||||
|
||||
/**
|
||||
* @brief QueuedProcessManager class constructor
|
||||
|
@ -44,7 +44,8 @@ class QueuedUser : public QObject
|
||||
Q_PROPERTY(QString password READ password WRITE setPassword)
|
||||
Q_PROPERTY(uint permissions READ permissions WRITE setPermissions)
|
||||
// limits
|
||||
Q_PROPERTY(QueuedLimits::Limits limits READ limits WRITE setLimits)
|
||||
Q_PROPERTY(QString limits READ limits WRITE setLimits)
|
||||
Q_PROPERTY(QueuedLimits::Limits nativeLimtis READ nativeLimits)
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -66,7 +67,7 @@ public:
|
||||
QString email;
|
||||
QString password;
|
||||
uint permissions;
|
||||
QueuedLimits::Limits limits;
|
||||
QString limits;
|
||||
} QueuedUserDefinitions;
|
||||
|
||||
/**
|
||||
@ -144,6 +145,11 @@ public:
|
||||
* @return name of user associated with system one
|
||||
*/
|
||||
QString name() const;
|
||||
/**
|
||||
* @brief user limits
|
||||
* @return user limits in native format
|
||||
*/
|
||||
QueuedLimits::Limits nativeLimits() const;
|
||||
/**
|
||||
* @brief user password
|
||||
* @return SHA512 of user password
|
||||
@ -159,7 +165,7 @@ public:
|
||||
* @brief user limits
|
||||
* @return user limits
|
||||
*/
|
||||
QueuedLimits::Limits limits() const;
|
||||
QString limits() const;
|
||||
// main properties
|
||||
/**
|
||||
* @brief set user email
|
||||
@ -191,7 +197,7 @@ public:
|
||||
* @param _limit
|
||||
* new user limits
|
||||
*/
|
||||
void setLimits(const QueuedLimits::Limits &_limits);
|
||||
void setLimits(const QString &_limits);
|
||||
/**
|
||||
* @brief equal operator implementation
|
||||
* @param _other
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
#include "queued/Queued.h"
|
||||
#include <queued/QueuedConfiguration.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -53,7 +54,28 @@ QVariant QueuedAdvancedSettings::get(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for key" << _key;
|
||||
|
||||
return m_values.value(_key.toLower(), QVariant());
|
||||
QString key = _key.toLower();
|
||||
if (m_values.contains(key))
|
||||
return m_values.value(key);
|
||||
else
|
||||
return QueuedCfg::QueuedSettingsDefaults[internalId(_key)].defaultValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn get
|
||||
*/
|
||||
QVariant QueuedAdvancedSettings::get(const QueuedCfg::QueuedSettings _key) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for key" << static_cast<int>(_key);
|
||||
|
||||
for (auto &key : QueuedCfg::QueuedSettingsDefaults.keys()) {
|
||||
if (QueuedCfg::QueuedSettingsDefaults[key].id != _key)
|
||||
continue;
|
||||
return get(key);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +90,24 @@ long long QueuedAdvancedSettings::id(const QString &_key) const
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn internalId
|
||||
*/
|
||||
QString QueuedAdvancedSettings::internalId(const QString &_key)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for key" << _key;
|
||||
|
||||
QString key = _key.toLower();
|
||||
for (auto &internal : QueuedCfg::QueuedSettingsDefaults.keys()) {
|
||||
if (internal.toLower() != key)
|
||||
continue;
|
||||
return internal;
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn set
|
||||
*/
|
||||
@ -76,7 +116,8 @@ void QueuedAdvancedSettings::set(const QString &_key, const QVariant &_value)
|
||||
qCDebug(LOG_LIB) << "Set value" << _value << "for key" << _key;
|
||||
|
||||
m_values[_key.toLower()] = _value;
|
||||
emit(valueUpdated(_key, _value));
|
||||
auto id = QueuedCfg::QueuedSettingsDefaults[internalId(_key)].id;
|
||||
emit(valueUpdated(id, _value));
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,9 +100,10 @@ bool QueuedCore::addTask(
|
||||
return false;
|
||||
}
|
||||
auto taskLimits = QueuedLimits::minimalLimits(
|
||||
_limits, user->limits(),
|
||||
_limits, user->nativeLimits(),
|
||||
QueuedLimits::Limits(
|
||||
m_advancedSettings->get(QString("DefaultLimits")).toString()));
|
||||
m_advancedSettings->get(QueuedCfg::QueuedSettings::DefaultLimits)
|
||||
.toString()));
|
||||
QVariantHash properties = {{"user", _userId},
|
||||
{"command", _command},
|
||||
{"commandArguments", _arguments},
|
||||
@ -408,6 +409,17 @@ bool QueuedCore::editUserPermission(
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn option
|
||||
*/
|
||||
QVariant QueuedCore::option(const QString &_key)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Look for option" << _key;
|
||||
|
||||
return m_advancedSettings->get(_key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn startTask
|
||||
*/
|
||||
@ -525,6 +537,8 @@ void QueuedCore::deinit()
|
||||
QDBusConnection::sessionBus().unregisterService(QueuedConfig::DBUS_SERVICE);
|
||||
|
||||
// delete objects now
|
||||
if (m_databaseManager)
|
||||
delete m_databaseManager;
|
||||
if (m_reports)
|
||||
delete m_reports;
|
||||
if (m_processes)
|
||||
@ -558,8 +572,9 @@ void QueuedCore::init(const QString &_configuration)
|
||||
// settings update notifier
|
||||
m_connections += connect(
|
||||
m_advancedSettings,
|
||||
SIGNAL(valueUpdated(const QString &, const QVariant &)), this,
|
||||
SLOT(updateSettings(const QString &, const QVariant &)));
|
||||
SIGNAL(valueUpdated(const QueuedCfg::QueuedSettings, const QVariant &)),
|
||||
this, SLOT(updateSettings(const QueuedCfg::QueuedSettings,
|
||||
const QVariant &)));
|
||||
|
||||
// dbus session
|
||||
initDBus();
|
||||
@ -569,21 +584,35 @@ void QueuedCore::init(const QString &_configuration)
|
||||
/**
|
||||
* @fn updateSettings
|
||||
*/
|
||||
void QueuedCore::updateSettings(const QString &_key, const QVariant &_value)
|
||||
void QueuedCore::updateSettings(const QueuedCfg::QueuedSettings _key,
|
||||
const QVariant &_value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Received update for" << _key << "with value" << _value;
|
||||
qCDebug(LOG_LIB) << "Received update for" << static_cast<int>(_key)
|
||||
<< "with value" << _value;
|
||||
|
||||
// FIXME propbably there is a better way to change settings
|
||||
QString key = _key.toLower();
|
||||
if (key == QString("defaultlimits"))
|
||||
;
|
||||
else if (key == QString("tokenexpiration"))
|
||||
m_users->setTokenExpiration(_value.toLongLong());
|
||||
else if (key == QString("onexitaction"))
|
||||
switch (_key) {
|
||||
case QueuedCfg::QueuedSettings::Invalid:
|
||||
break;
|
||||
case QueuedCfg::QueuedSettings::DatabaseInterval:
|
||||
m_databaseManager->setInterval(_value.toLongLong());
|
||||
break;
|
||||
case QueuedCfg::QueuedSettings::DefaultLimits:
|
||||
break;
|
||||
case QueuedCfg::QueuedSettings::KeepTasks:
|
||||
m_databaseManager->setKeepTasks(_value.toLongLong());
|
||||
break;
|
||||
case QueuedCfg::QueuedSettings::KeepUsers:
|
||||
m_databaseManager->setKeepUsers(_value.toLongLong());
|
||||
break;
|
||||
case QueuedCfg::QueuedSettings::OnExitAction:
|
||||
m_processes->setOnExitAction(
|
||||
static_cast<QueuedProcessManager::OnExitAction>(_value.toInt()));
|
||||
else
|
||||
qCInfo(LOG_LIB) << "Unused key" << _key;
|
||||
break;
|
||||
case QueuedCfg::QueuedSettings::TokenExpiration:
|
||||
m_users->setTokenExpiration(_value.toLongLong());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -685,7 +714,8 @@ void QueuedCore::initProcesses()
|
||||
{
|
||||
// init processes
|
||||
auto onExitAction = static_cast<QueuedProcessManager::OnExitAction>(
|
||||
m_advancedSettings->get(QString("OnExitAction")).toInt());
|
||||
m_advancedSettings->get(QueuedCfg::QueuedSettings::OnExitAction)
|
||||
.toInt());
|
||||
|
||||
m_processes = new QueuedProcessManager(this, onExitAction);
|
||||
auto dbProcesses = m_database->get(
|
||||
@ -735,6 +765,8 @@ void QueuedCore::initSettings(const QString &_configuration)
|
||||
|
||||
// report manager
|
||||
m_reports = new QueuedReportManager(this, m_database);
|
||||
// database manager
|
||||
m_databaseManager = new QueuedDatabaseManager(this, m_database);
|
||||
}
|
||||
|
||||
|
||||
@ -745,7 +777,8 @@ void QueuedCore::initUsers()
|
||||
{
|
||||
// load users and tokens
|
||||
auto expiry
|
||||
= m_advancedSettings->get(QString("TokenExpiration")).toLongLong();
|
||||
= m_advancedSettings->get(QueuedCfg::QueuedSettings::TokenExpiration)
|
||||
.toLongLong();
|
||||
|
||||
m_users = new QueuedUserManager(this);
|
||||
m_users->setTokenExpiration(expiry);
|
||||
|
@ -134,7 +134,7 @@ bool QueuedCoreInterface::TaskEdit(
|
||||
if (state > 0)
|
||||
data[QString("state")] = state;
|
||||
// append limits now
|
||||
auto limits = task->limits();
|
||||
auto limits = task->nativeLimits();
|
||||
if (cpu > -1)
|
||||
limits.cpu = cpu;
|
||||
if (gpu > -1)
|
||||
@ -228,7 +228,7 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||
if (!email.isEmpty())
|
||||
data[QString("email")] = email;
|
||||
// append limits now
|
||||
auto limits = user->limits();
|
||||
auto limits = user->nativeLimits();
|
||||
if (cpu > -1)
|
||||
limits.cpu = cpu;
|
||||
if (gpu > -1)
|
||||
|
@ -47,6 +47,17 @@ QueuedCorePropertiesInterface::~QueuedCorePropertiesInterface()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn Option
|
||||
*/
|
||||
QDBusVariant QueuedCorePropertiesInterface::Option(const QString &property)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Get property" << property;
|
||||
|
||||
return QDBusVariant(m_core->option(property));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskProperty
|
||||
*/
|
||||
|
158
sources/queued/src/QueuedDatabaseManager.cpp
Normal file
158
sources/queued/src/QueuedDatabaseManager.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
/**
|
||||
* @file QueuedDatabaseManager.cpp
|
||||
* Source code of queued library
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright GPLv3
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#include "queued/Queued.h"
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedDatabaseManager
|
||||
*/
|
||||
/**
|
||||
* @fn QueuedDatabaseManager
|
||||
*/
|
||||
QueuedDatabaseManager::QueuedDatabaseManager(QObject *parent,
|
||||
QueuedDatabase *database)
|
||||
: QObject(parent)
|
||||
, m_database(database)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_timer.setSingleShot(false);
|
||||
// connections
|
||||
connect(&m_timer, SIGNAL(timeout()), this, SLOT(cleanup()));
|
||||
|
||||
startWorker();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~QueuedDatabaseManager
|
||||
*/
|
||||
QueuedDatabaseManager::~QueuedDatabaseManager()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(cleanup()));
|
||||
|
||||
m_timer.stop();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn startWorker
|
||||
*/
|
||||
void QueuedDatabaseManager::startWorker()
|
||||
{
|
||||
// stop timer first
|
||||
if (m_timer.isActive())
|
||||
m_timer.stop();
|
||||
|
||||
// update interval
|
||||
m_timer.setInterval(std::chrono::milliseconds(interval()));
|
||||
// start timer
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn interval
|
||||
*/
|
||||
long long QueuedDatabaseManager::interval() const
|
||||
{
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn keepTasks
|
||||
*/
|
||||
long long QueuedDatabaseManager::keepTasks() const
|
||||
{
|
||||
return m_keepTasks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn keepUsers
|
||||
*/
|
||||
long long QueuedDatabaseManager::keepUsers() const
|
||||
{
|
||||
return m_keepUsers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setInterval
|
||||
*/
|
||||
void QueuedDatabaseManager::setInterval(const long long _interval)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set interval to" << _interval;
|
||||
|
||||
m_interval = _interval;
|
||||
// update timer now
|
||||
startWorker();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setKeepTasks
|
||||
*/
|
||||
void QueuedDatabaseManager::setKeepTasks(const long long _keepInterval)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set keep tasks to" << _keepInterval;
|
||||
|
||||
m_keepTasks = _keepInterval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setKeepUsers
|
||||
*/
|
||||
void QueuedDatabaseManager::setKeepUsers(const long long _keepInterval)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set keep users to" << _keepInterval;
|
||||
|
||||
m_keepUsers = _keepInterval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn cleanup
|
||||
*/
|
||||
void QueuedDatabaseManager::cleanup()
|
||||
{
|
||||
// tasks
|
||||
if (keepTasks() > 0) {
|
||||
QDateTime time = QDateTime::currentDateTimeUtc().addMSecs(-keepTasks());
|
||||
m_database->removeTasks(time);
|
||||
}
|
||||
// tokens
|
||||
m_database->removeTokens();
|
||||
// users
|
||||
if (keepUsers() > 0) {
|
||||
QDateTime time = QDateTime::currentDateTimeUtc().addMSecs(-keepUsers());
|
||||
m_database->removeUsers(time);
|
||||
}
|
||||
}
|
@ -118,12 +118,21 @@ uint QueuedProcess::gid() const
|
||||
/**
|
||||
* @fn limits
|
||||
*/
|
||||
QueuedLimits::Limits QueuedProcess::limits() const
|
||||
QString QueuedProcess::limits() const
|
||||
{
|
||||
return m_definitions.limits;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn nativeLimits
|
||||
*/
|
||||
QueuedLimits::Limits QueuedProcess::nativeLimits() const
|
||||
{
|
||||
return QueuedLimits::Limits(limits());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn nice
|
||||
*/
|
||||
@ -227,9 +236,9 @@ void QueuedProcess::setGid(const uint _gid)
|
||||
/**
|
||||
* setLimits
|
||||
*/
|
||||
void QueuedProcess::setLimits(const QueuedLimits::Limits &_limits)
|
||||
void QueuedProcess::setLimits(const QString &_limits)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set process limits" << _limits.toString();
|
||||
qCDebug(LOG_LIB) << "Set process limits" << _limits;
|
||||
|
||||
m_definitions.limits = _limits;
|
||||
}
|
||||
|
@ -67,8 +67,7 @@ QueuedProcess *QueuedProcessManager::add(const QVariantHash &_properties,
|
||||
QChar('\x01'));
|
||||
defs.workingDirectory = _properties[QString("workDirectory")].toString();
|
||||
defs.nice = _properties[QString("nice")].toUInt();
|
||||
defs.limits
|
||||
= QueuedLimits::Limits(_properties[QString("limits")].toString());
|
||||
defs.limits = _properties[QString("limits")].toString();
|
||||
// user data
|
||||
defs.uid = _properties[QString("uid")].toUInt();
|
||||
defs.gid = _properties[QString("gid")].toUInt();
|
||||
|
@ -167,6 +167,15 @@ QString QueuedUser::name() const
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn nativeLimits
|
||||
*/
|
||||
QueuedLimits::Limits QueuedUser::nativeLimits() const
|
||||
{
|
||||
return QueuedLimits::Limits(limits());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn password
|
||||
*/
|
||||
@ -188,7 +197,7 @@ uint QueuedUser::permissions() const
|
||||
/**
|
||||
* @fn limits
|
||||
*/
|
||||
QueuedLimits::Limits QueuedUser::limits() const
|
||||
QString QueuedUser::limits() const
|
||||
{
|
||||
return m_definitions.limits;
|
||||
}
|
||||
@ -241,9 +250,9 @@ void QueuedUser::setPermissions(const uint _permissions)
|
||||
/**
|
||||
* @fn setLimits
|
||||
*/
|
||||
void QueuedUser::setLimits(const QueuedLimits::Limits &_limits)
|
||||
void QueuedUser::setLimits(const QString &_limits)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "New user limits" << _limits.toString();
|
||||
qCDebug(LOG_LIB) << "New user limits" << _limits;
|
||||
|
||||
m_definitions.limits = _limits;
|
||||
}
|
||||
|
@ -66,8 +66,7 @@ QueuedUser *QueuedUserManager::add(const QVariantHash &_properties,
|
||||
defs.email = _properties[QString("email")].toString();
|
||||
defs.password = _properties[QString("password")].toString();
|
||||
defs.permissions = _properties[QString("permissions")].toUInt();
|
||||
defs.limits
|
||||
= QueuedLimits::Limits(_properties[QString("limits")].toString());
|
||||
defs.limits = _properties[QString("limits")].toString();
|
||||
|
||||
return add(defs, _id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user