mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
add proto for task run
This commit is contained in:
parent
2d8d501f02
commit
9000bf08a4
@ -121,6 +121,10 @@ public:
|
||||
* task index
|
||||
*/
|
||||
void remove(const long long _index);
|
||||
/**
|
||||
* @brief select and start task automatically
|
||||
*/
|
||||
void start();
|
||||
/**
|
||||
* @brief force start task
|
||||
* @param _index
|
||||
@ -156,6 +160,11 @@ public:
|
||||
* new command line
|
||||
*/
|
||||
void setProcessLine(const QString _processLine);
|
||||
/**
|
||||
* @brief get used limits
|
||||
* @return used system limits
|
||||
*/
|
||||
QueuedLimits::Limits usedLimits();
|
||||
|
||||
signals:
|
||||
/**
|
||||
|
@ -530,6 +530,9 @@ void QueuedCore::init(const QString &_configuration)
|
||||
|
||||
// dbus session
|
||||
initDBus();
|
||||
|
||||
// run!
|
||||
m_processes->start();
|
||||
}
|
||||
|
||||
|
||||
|
@ -170,6 +170,45 @@ void QueuedProcessManager::remove(const long long _index)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn start
|
||||
*/
|
||||
void QueuedProcessManager::start()
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Start random task";
|
||||
|
||||
long long index = -1;
|
||||
// gather used resources
|
||||
QueuedLimits::Limits limits = usedLimits();
|
||||
double weightedCpu
|
||||
= limits.cpu == 0 ? 0.0 : QueuedSystemInfo::cpuWeight(limits.cpu);
|
||||
double weightedMemory = limits.memory == 0
|
||||
? 0.0
|
||||
: QueuedSystemInfo::memoryWeight(limits.memory);
|
||||
|
||||
auto tasks = processes().values();
|
||||
for (auto pr : tasks) {
|
||||
// check limits first
|
||||
if (((1.0 - weightedCpu)
|
||||
< QueuedSystemInfo::cpuWeight(pr->nativeLimits().cpu))
|
||||
&& ((1.0 - weightedMemory)
|
||||
< QueuedSystemInfo::memoryWeight(pr->nativeLimits().memory)))
|
||||
continue;
|
||||
// now check nice level
|
||||
if ((index > -1) && (pr->nice() < process(index)->nice()))
|
||||
continue;
|
||||
// now check index value
|
||||
if ((index > -1) && (pr->index() > index))
|
||||
continue;
|
||||
// hmmm, looks like we found a candidate
|
||||
index = pr->index();
|
||||
}
|
||||
|
||||
if (index > -1)
|
||||
return start(index);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn start
|
||||
*/
|
||||
@ -184,6 +223,7 @@ void QueuedProcessManager::start(const long long _index)
|
||||
}
|
||||
|
||||
pr->start();
|
||||
emit(taskStartTimeReceived(_index, QDateTime::currentDateTimeUtc()));
|
||||
}
|
||||
|
||||
|
||||
@ -253,6 +293,52 @@ void QueuedProcessManager::setProcessLine(const QString _processLine)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn usedLimits
|
||||
*/
|
||||
QueuedLimits::Limits QueuedProcessManager::usedLimits()
|
||||
{
|
||||
auto tasks = processes().values();
|
||||
long long cpu = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
? value + process->nativeLimits().cpu
|
||||
: value;
|
||||
});
|
||||
long long gpu = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
? value + process->nativeLimits().gpu
|
||||
: value;
|
||||
});
|
||||
long long memory = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
? value + process->nativeLimits().memory
|
||||
: value;
|
||||
});
|
||||
long long gpumemory = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
? value + process->nativeLimits().gpumemory
|
||||
: value;
|
||||
});
|
||||
long long storage = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
? value + process->nativeLimits().storage
|
||||
: value;
|
||||
});
|
||||
|
||||
return QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn taskFinished
|
||||
*/
|
||||
@ -269,7 +355,6 @@ void QueuedProcessManager::taskFinished(const int _exitCode,
|
||||
pr->setEndTime(endTime);
|
||||
emit(taskStopTimeReceived(_index, endTime));
|
||||
}
|
||||
// TODO implementation
|
||||
// TODO emit signal for new task here
|
||||
// emit(taskStartTimeReceived(_index, QDateTime::currentDateTimeUtc()));
|
||||
|
||||
start();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user