From 52ae9e8e5c7179e56963d8fc464ebc765ab18af6 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 4 Oct 2017 10:56:43 -0400 Subject: [PATCH] Add ability to specify working directory to the dispatcher, and update the new fetch_ports API call. --- src/server/Dispatcher.cpp | 19 ++++++++++--------- src/server/Dispatcher.h | 10 +++++----- src/server/library/sysadm-systemmanager.cpp | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/server/Dispatcher.cpp b/src/server/Dispatcher.cpp index 38c92cd..98ba91f 100644 --- a/src/server/Dispatcher.cpp +++ b/src/server/Dispatcher.cpp @@ -196,31 +196,32 @@ void Dispatcher::stop(){ } //Overloaded Main Calling Functions (single command, or multiple in-order commands) -DProcess* Dispatcher::queueProcess(QString ID, QString cmd){ - return queueProcess(NO_QUEUE, ID, QStringList() << cmd); +DProcess* Dispatcher::queueProcess(QString ID, QString cmd, QString workdir){ + return queueProcess(NO_QUEUE, ID, QStringList() << cmd, workdir); } -DProcess* Dispatcher::queueProcess(QString ID, QStringList cmds){ - return queueProcess(NO_QUEUE, ID, cmds); +DProcess* Dispatcher::queueProcess(QString ID, QStringList cmds, QString workdir){ + return queueProcess(NO_QUEUE, ID, cmds, workdir); } -DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QString cmd){ - return queueProcess(queue, ID, QStringList() << cmd); +DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QString cmd, QString workdir){ + return queueProcess(queue, ID, QStringList() << cmd, workdir); } -DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QStringList cmds){ +DProcess* Dispatcher::queueProcess(Dispatcher::PROC_QUEUE queue, QString ID, QStringList cmds, QString workdir){ //This is the primary queueProcess() function - all the overloads end up here to do the actual work //For multi-threading, need to emit a signal/slot for this action (object creations need to be in same thread as parent) //qDebug() << "Queue Process:" << queue << ID << cmds; - DProcess *P = createProcess(ID, cmds); + DProcess *P = createProcess(ID, cmds, workdir); this->emit mkprocs(queue, P); return P; } // === PRIVATE === //Simplification routine for setting up a process -DProcess* Dispatcher::createProcess(QString ID, QStringList cmds){ +DProcess* Dispatcher::createProcess(QString ID, QStringList cmds, QString workdir){ DProcess *P = new DProcess(); P->moveToThread(this->thread()); P->cmds = cmds; P->ID = ID; + if(!workdir.isEmpty()){ P->setWorkingDirectory(workdir); } return P; } diff --git a/src/server/Dispatcher.h b/src/server/Dispatcher.h index 6f1fe55..2e7a796 100644 --- a/src/server/Dispatcher.h +++ b/src/server/Dispatcher.h @@ -70,10 +70,10 @@ public slots: void stop(); //save any currently-unrun processes for next time //Main Calling Functions (single command, or multiple in-order commands) - DProcess* queueProcess(QString ID, QString cmd); //uses NO_QUEUE - DProcess* queueProcess(QString ID, QStringList cmds); //uses NO_QUEUE - DProcess* queueProcess(Dispatcher::PROC_QUEUE, QString ID, QString cmd); - DProcess* queueProcess(Dispatcher::PROC_QUEUE, QString ID, QStringList cmds); + DProcess* queueProcess(QString ID, QString cmd, QString workdir = ""); //uses NO_QUEUE + DProcess* queueProcess(QString ID, QStringList cmds, QString workdir = ""); //uses NO_QUEUE + DProcess* queueProcess(Dispatcher::PROC_QUEUE, QString ID, QString cmd, QString workdir = ""); + DProcess* queueProcess(Dispatcher::PROC_QUEUE, QString ID, QStringList cmds, QString workdir = ""); private: // Queue file @@ -83,7 +83,7 @@ private: QHash > HASH; //Simplification routine for setting up a process - DProcess* createProcess(QString ID, QStringList cmds); + DProcess* createProcess(QString ID, QStringList cmds, QString workdir = ""); QJsonObject CreateDispatcherEventNotification(QString, QJsonObject); // Functions to do parsing out dispatcher queued tasks diff --git a/src/server/library/sysadm-systemmanager.cpp b/src/server/library/sysadm-systemmanager.cpp index 4ea2e16..57feae4 100644 --- a/src/server/library/sysadm-systemmanager.cpp +++ b/src/server/library/sysadm-systemmanager.cpp @@ -449,7 +449,7 @@ QJsonObject SysMgmt::fetchPortsTree(QString altDir){ } //Now update the tree with git QString ID = "system_fetch_ports_tree"; - DISPATCHER->queueProcess(ID, QStringList() << "cd \""+altDir+"\"" << "git fetch" << "git pull" ); + DISPATCHER->queueProcess(ID, "git pull origin", altDir ); out.insert("result","process_started"); out.insert("process_id",ID); return out;