Introduced tick counter and ExecuteSchedules for execution of recurrent no argument tasks
parent
50ad33ac33
commit
9f20211bf4
|
@ -59,10 +59,13 @@ func main() {
|
|||
|
||||
printDbDetails()
|
||||
|
||||
tick := 0
|
||||
|
||||
// infinite loop
|
||||
for {
|
||||
|
||||
systemIterator(name)
|
||||
tick++ // Tick is an int, so eventually will "go out of ticks?" Maybe we want to reset the ticks every once in a while, to avoid working with big numbers...
|
||||
systemIterator(name, tick)
|
||||
|
||||
}
|
||||
|
||||
|
@ -98,13 +101,16 @@ func isDatabaseReady() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func systemIterator(name *string) {
|
||||
func systemIterator(name *string, tick int) {
|
||||
|
||||
log.Printf("Tick is %d", tick)
|
||||
|
||||
if isSystemReady() {
|
||||
// Wait about 60 seconds before trying again.
|
||||
log.Printf("System not ready. Next try will be executed in 60 seconds")
|
||||
time.Sleep(defaultNotReadySleepTime)
|
||||
} else {
|
||||
tasks.ExecuteSchedules(tick)
|
||||
// Wait about 1 second before resumming operations.
|
||||
log.Printf("Next instruction will be executed 1 second")
|
||||
time.Sleep(defaultSleepTime)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue