Checking for online working
This commit is contained in:
@@ -32,11 +32,12 @@ async def main():
|
||||
print(dumps(online_devices,indent=4))
|
||||
else:
|
||||
print(dumps(online_devices))
|
||||
else:
|
||||
print("No LO flag.")
|
||||
|
||||
if args.run:
|
||||
print("run command")
|
||||
if not args.command or not args.nodeids:
|
||||
return
|
||||
|
||||
print(args.nodeids)
|
||||
|
||||
await session.close()
|
||||
|
||||
|
||||
Binary file not shown.
3
server/python.sh
Executable file
3
server/python.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
./../runner/venv/bin/python3 ./../runner/runner.py
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"ghostrunner-server/modules/restapi"
|
||||
"ghostrunner-server/modules/timekeeper"
|
||||
"ghostrunner-server/modules/utilities"
|
||||
"ghostrunner-server/modules/wrapper"
|
||||
"log"
|
||||
)
|
||||
|
||||
@@ -31,15 +30,5 @@ func main() {
|
||||
log.Println(utilities.InfoTag, "Letting TimeKeeper take over...")
|
||||
log.Println(utilities.InfoTag, fmt.Sprintf("Interval set at: %d seconds.", cfg.Interval))
|
||||
|
||||
onDevices, err := wrapper.PyListOnline(cfg.PyVenvName)
|
||||
if err != nil {
|
||||
log.Println(utilities.ErrTag, err)
|
||||
}
|
||||
|
||||
for index, device := range onDevices.OnlineDevices {
|
||||
log.Println(index, device)
|
||||
}
|
||||
log.Println(len(onDevices.OnlineDevices))
|
||||
|
||||
timekeeper.KeepTime(cfg.Interval)
|
||||
timekeeper.KeepTime(cfg.Interval, cfg)
|
||||
}
|
||||
|
||||
35
server/src/modules/timekeeper/routine.go
Normal file
35
server/src/modules/timekeeper/routine.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package timekeeper
|
||||
|
||||
import (
|
||||
"ghostrunner-server/modules/database"
|
||||
"ghostrunner-server/modules/utilities"
|
||||
"log"
|
||||
)
|
||||
|
||||
func routine(cfg utilities.ConfigStruct, pyListArgs []string) {
|
||||
d := listDevices(cfg, pyListArgs) // Retrieve the Online devices.
|
||||
curTasks := database.RetrieveTasks()
|
||||
|
||||
for index, device := range d.OnlineDevices {
|
||||
log.Println(index, device)
|
||||
}
|
||||
|
||||
for index, task := range curTasks {
|
||||
log.Println(index, task)
|
||||
for _, nodeid := range task.Nodeids {
|
||||
if isNodeOnline(nodeid, d.OnlineDevices) {
|
||||
log.Printf("NodeID %s is online\n", nodeid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func isNodeOnline(nodeid string, onlineDevices []utilities.Device) bool {
|
||||
for _, device := range onlineDevices {
|
||||
if device.NodeID == nodeid {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -2,11 +2,17 @@ package timekeeper
|
||||
|
||||
import (
|
||||
"ghostrunner-server/modules/utilities"
|
||||
"ghostrunner-server/modules/wrapper"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func KeepTime(interval int) {
|
||||
var ( // Debugging
|
||||
pyListArgs = strings.Fields("-lo")
|
||||
)
|
||||
|
||||
func KeepTime(interval int, cfg utilities.ConfigStruct) {
|
||||
transInterval := time.Duration(interval) * time.Second
|
||||
|
||||
ticker := time.NewTicker(transInterval)
|
||||
@@ -14,5 +20,16 @@ func KeepTime(interval int) {
|
||||
|
||||
for t := range ticker.C {
|
||||
log.Println(utilities.InfoTag, "Tick at:", t)
|
||||
log.Println(utilities.InfoTag, "Starting Routine.")
|
||||
routine(cfg, pyListArgs)
|
||||
}
|
||||
}
|
||||
|
||||
func listDevices(cfg utilities.ConfigStruct, pyArgs []string) utilities.PyOnlineDevices {
|
||||
onDevices, err := wrapper.PyListOnline(cfg.PyVenvName, pyArgs)
|
||||
if err != nil {
|
||||
log.Println(utilities.ErrTag, err)
|
||||
}
|
||||
|
||||
return onDevices
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ type Device struct {
|
||||
}
|
||||
|
||||
type PyOnlineDevices struct {
|
||||
OnlineDevices []Device `json:"online_devices"`
|
||||
TotalDevices int `json:"total_devices"`
|
||||
OnlineDevices []Device `json:"online_devices"`
|
||||
OfflineDevices []Device `json:"offline_devices"`
|
||||
TotalDevices int `json:"total_devices"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"ghostrunner-server/modules/utilities"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
@@ -12,11 +13,14 @@ const (
|
||||
pyFile = "./../runner/runner.py"
|
||||
)
|
||||
|
||||
func PyListOnline(venvName string) (utilities.PyOnlineDevices, error) {
|
||||
func PyListOnline(venvName string, pyArgs []string) (utilities.PyOnlineDevices, error) {
|
||||
pyBin := fmt.Sprintf("./../runner/%s/bin/python", venvName)
|
||||
cmd := exec.Command(pyBin, pyFile, "-lo")
|
||||
runtimeArgs := append([]string{pyFile}, pyArgs...)
|
||||
|
||||
cmd := exec.Command(pyBin, runtimeArgs...)
|
||||
|
||||
rawData, err := cmd.CombinedOutput()
|
||||
log.Println(string(rawData))
|
||||
if err != nil {
|
||||
cwd, _ := os.Getwd()
|
||||
return utilities.PyOnlineDevices{}, fmt.Errorf("python execution failed, working directory: %s", cwd)
|
||||
|
||||
Reference in New Issue
Block a user