check scheduler
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
root
2024-08-08 13:33:06 +02:00
parent 6ede5795ba
commit e7f58109c2

View File

@@ -112,6 +112,37 @@ Function CheckDockerStatus()
End Function End Function
Function CheckScheduler()
Dim objExec, outputLine, allOutput
' WSL command to check Docker status
Dim WSLCommand
WSLCommand = "wsl.exe --user root --exec sh -c ""docker ps --format 'table {{.Names}}' | grep framework-scheduler"" "
' Execute the command
On Error Resume Next
Set objExec = objShell.Exec(WSLCommand)
allOutput = ""
' Loop through the command's output
Do While Not objExec.StdOut.AtEndOfStream
outputLine = objExec.StdOut.ReadLine()
allOutput = allOutput & outputLine & vbCrLf
Loop
logToFile(allOutput)
' Check if the output contains 'Server Version'
If InStr(allOutput, "framework-scheduler") > 0 Then
CheckScheduler = True
Else
CheckScheduler = False
End If
End Function
Sub logToFile(output) Sub logToFile(output)
' Log the output to a file (optional for debugging) ' Log the output to a file (optional for debugging)
@@ -136,9 +167,8 @@ Sub btnStart_OnClick
Exit Sub Exit Sub
End If End If
StartWSL StartInstall
'MsgBox "TEST STARTED",64,"DONE"
End Sub End Sub
Sub btnOpen_OnClick Sub btnOpen_OnClick
@@ -151,11 +181,14 @@ Sub ShowOutput(objExec)
exitCode = objExec.ExitCode exitCode = objExec.ExitCode
If exitCode = 0 Then If exitCode = 0 Then
' Read the output line by line ' Read the output line by line
outputLine = ""
Do While Not objExec.StdOut.AtEndOfStream Do While Not objExec.StdOut.AtEndOfStream
outputLine = outputLine & objExec.StdOut.ReadLine() & vbCrLf outputLine = outputLine & objExec.StdOut.ReadLine() & vbCrLf
Loop Loop
'WScript.Echo "Command executed successfully:" & vbCrLf & outputLine 'WScript.Echo "Command executed successfully:" & vbCrLf & outputLine
logToFile(outputLine)
Else Else
Dim errorLine Dim errorLine
errorLine = "" errorLine = ""
@@ -164,8 +197,11 @@ Sub ShowOutput(objExec)
Loop Loop
'WScript.Echo "Command failed with exit code: " & exitCode & vbCrLf & "Error Output:" & vbCrLf & errorLine 'WScript.Echo "Command failed with exit code: " & exitCode & vbCrLf & "Error Output:" & vbCrLf & errorLine
logToFile(errorLine)
End If End If
' Call JS function to display output because Echo doesn't work in hta ' Call JS function to display output because Echo doesn't work in hta
Call UpdateOutput(outputLine, errorLine) Call UpdateOutput(outputLine, errorLine)
@@ -185,42 +221,56 @@ Sub Delay(seconds)
Loop Loop
End Sub End Sub
Sub StartWSL() Sub StartInstall()
Dim WSL
'WSL = "wsl.exe --user root --exec docker ps > C:\Users\wslresult.txt" 'WSL = "wsl.exe --user root --exec docker ps > C:\Users\wslresult.txt"
'intReturn = objShell.Run(WSL, 0, True) 'intReturn = objShell.Run(WSL, 0, True)
Dim schedulerIsRunning
schedulerIsRunning = CheckScheduler()
If schedulerIsRunning Then
MsgBox "Scheduler is already running", vbInformation, "Docker Status"
WSL = "wsl.exe --user root --exec docker ps --format ""table {{.Names}}\t{{.Status}}"" " WSL = "wsl.exe --user root --exec docker ps --format ""table {{.Names}}\t{{.Status}}"" "
Set objExec = objShell.Exec(WSL) Set objExec = objShell.Exec(WSL)
outputLine = ""
ShowOutput(objExec) ShowOutput(objExec)
Else
MsgBox "Scheduler is not running", vbInformation, "Docker Status"
StartScheduler
End If
End Sub
Sub StartScheduler()
Dim WSL
WSL = "wsl.exe --user root --exec docker run -d -v /var/run/docker.sock:/var/run/docker.sock --env WEBSERVER_PORT=" & txtPort.value & " registry.format.hu/framework-scheduler" WSL = "wsl.exe --user root --exec docker run -d -v /var/run/docker.sock:/var/run/docker.sock --env WEBSERVER_PORT=" & txtPort.value & " registry.format.hu/framework-scheduler"
MsgBox WSL
intReturn = objShell.Run(WSL, 0, True) intReturn = objShell.Run(WSL, 0, True)
If Err.Number <> 0 Then If Err.Number <> 0 Then
MsgBox (Err.number & "-" & err.Description) MsgBox (Err.number & "-" & err.Description)
else else
MsgBox "Framework scheduler has started" MsgBox "Framework scheduler is starting..."
Delay 10
WSL = "wsl.exe --user root --exec docker logs framework-scheduler" WSL = "wsl.exe --user root --exec docker logs framework-scheduler"
Set objExec = objShell.Exec(WSL)
ShowOutput(objExec)
iterationCount = 0 iterationCount = 0
maxIterations = 12 ' Run for 1 minute (12 iterations of 5 seconds each) maxIterations = 12 ' Run for 1 minute (12 iterations of 5 seconds each)
Do 'Do
iterationCount = iterationCount + 1 'iterationCount = iterationCount + 1
Set objExec = objShell.Exec(WSL) 'Set objExec = objShell.Exec(WSL)
ShowOutput(objExec) 'ShowOutput(objExec)
MsgBox "Please wait"
'Delay 5 'Delay 5
If iterationCount >= maxIterations Then 'If iterationCount >= maxIterations Then
MsgBox "Max iterations reached, stopping script." ' MsgBox "Max iterations reached, stopping script."
Exit Do ' Exit Do
End If 'End If
Loop 'Loop
End If End If
End Sub End Sub
@@ -320,9 +370,9 @@ End Sub
var outputElement = document.getElementById('output'); var outputElement = document.getElementById('output');
if (output !== '') { if (output !== '') {
outputElement.innerText += output; outputElement.innerText = output;
} else if (errorOutput !== '') { } else if (errorOutput !== '') {
outputElement.innerText += errorOutput; outputElement.innerText = errorOutput;
} else { } else {
outputElement.innerText = '...'; outputElement.innerText = '...';
} }