Introduced tick counter and ExecuteSchedules for execution of recurrent no argument tasks

This commit is contained in:
Paulo Truta
2021-02-15 18:14:46 +00:00
parent 50ad33ac33
commit 9f20211bf4
2 changed files with 42 additions and 3 deletions
+34 -1
View File
@@ -143,7 +143,7 @@ func ExecuteTask(task Task) Task {
if task.Result.Valid {
db.Query("Update tasks SET status = 2, result = '" + task.Result.String + "' WHERE ID = " + strconv.Itoa(task.ID) + ";")
} else {
db.Query("Update tasks SET status = 2, result = 'Invalid Task' WHERE ID = " + strconv.Itoa(task.ID) + ";")
db.Query("Update tasks SET status = 3, result = 'Error' WHERE ID = " + strconv.Itoa(task.ID) + ";")
}
if err != nil {
@@ -156,6 +156,24 @@ func ExecuteTask(task Task) Task {
}
// ExecuteSchedules - Run Specific tasks without input each multiple x of ticks.
func ExecuteSchedules(tick int) {
if tick%30 == 0 {
// Executing every 30 ticks
taskGetEdgeApps()
}
if tick%60 == 0 {
// Every 60 ticks...
}
// Just add a schedule here if you need a custom one (every "tick hour", every "tick day", etc...)
}
func executeCommand(command string, args []string) string {
cmd := exec.Command(command, args...)
var out bytes.Buffer
@@ -189,6 +207,21 @@ func taskSetupTunnel(args taskSetupTunnelArgs) string {
}
func taskGetEdgeApps() string {
fmt.Println("Executing taskGetEdgeApps")
// Building list of available edgeapps in the system.
// Querying to see which apps are running.
// cmdargs = []string{"ps", "-a"}
// executeCommand("docker", cmdargs)
// (...)
// Saving information in the "options" table.
return "OK"
}
func taskStartEdgeApp() string {
return "OK"