feat(controller): update scheduler added
This commit is contained in:
@@ -6,11 +6,13 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
"github.com/joho/godotenv"
|
||||
"lst.net/pkg"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -90,13 +92,42 @@ func main() {
|
||||
registerUpdateChannel(server)
|
||||
|
||||
// Broadcast logs to room
|
||||
go func() {
|
||||
for i := 0; ; i++ {
|
||||
time.Sleep(2 * time.Second)
|
||||
msg := fmt.Sprintf("Log line %d @ %s", i, time.Now().Format(time.RFC3339))
|
||||
server.BroadcastToRoom("/", "logs", "logs", msg)
|
||||
// go func() {
|
||||
// for i := 0; ; i++ {
|
||||
// time.Sleep(2 * time.Second)
|
||||
// msg := fmt.Sprintf("Log line %d @ %s", i, time.Now().Format(time.RFC3339))
|
||||
// server.BroadcastToRoom("/", "logs", "logs", msg)
|
||||
// }
|
||||
// }()
|
||||
// go pkg.JobScheduler(server, "0 9 * * *", func() {
|
||||
// fmt.Println("This is the time checker")
|
||||
// server.BroadcastToRoom("/", "logs", "logs", "Just ran at 9:00 for example")
|
||||
// })
|
||||
|
||||
// schedule the update checker
|
||||
|
||||
go pkg.JobScheduler(server, "0 8 * * 1-4", func() {
|
||||
host, err := os.Hostname()
|
||||
if err != nil {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", "Could not retrieve hostname")
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
if strings.Contains(host, "VMS") || strings.Contains(host, "vms") {
|
||||
fmt.Println("On a server ok to start the update job")
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", "On a server ok to start the update job")
|
||||
updates := UpdateApp(server)
|
||||
|
||||
fmt.Println("📦 Starting update loop")
|
||||
for msg := range updates { // this will block until the channel closes
|
||||
fmt.Println(msg)
|
||||
server.BroadcastToRoom("/", "logs", "logs", msg)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Update process finished")
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// Broadcast errors to room
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user