Skip to content

Commit

Permalink
add debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousm4x committed Jan 29, 2023
1 parent 18ef9f8 commit 969d154
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/cronjobs/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func RunPing(app *pocketbase.PocketBase) {
}(device)
}
})
logger.Debug.Println("CronPing entries:", CronPing.Entries())
CronPing.Run()
}

Expand Down Expand Up @@ -98,5 +99,6 @@ func RunWakeShutdown() {
})
}
}
logger.Debug.Println("CronWakeShutdown entries:", CronWakeShutdown.Entries())
CronWakeShutdown.Run()
}
2 changes: 2 additions & 0 deletions backend/networking/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"time"

"github.com/pocketbase/pocketbase/models"
"github.com/seriousm4x/upsnap/backend/logger"
)

func ShutdownDevice(device *models.Record) error {
logger.Debug.Println("shutdown triggered for", device.GetString("name"))
shutdown_cmd := device.GetString("shutdown_cmd")
if shutdown_cmd == "" {
return fmt.Errorf("%s: no shutdown_cmd definded", device.GetString("name"))
Expand Down
2 changes: 2 additions & 0 deletions backend/networking/wake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"time"

"github.com/pocketbase/pocketbase/models"
"github.com/seriousm4x/upsnap/backend/logger"
)

func WakeDevice(device *models.Record) error {
logger.Debug.Println("wake triggered for", device.GetString("name"))
err := SendMagicPacket(device)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions backend/pb/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ func StartPocketBase(distDirFS fs.FS) {
// using this outside App.OnBeforeServe() would not work
App.OnModelAfterUpdate().Add(func(e *core.ModelEvent) error {
if e.Model.TableName() == "settings" {
logger.Debug.Println("restart CronPing")
for _, job := range cronjobs.CronPing.Entries() {
cronjobs.CronPing.Remove(job.ID)
}
go cronjobs.RunPing(App)
} else if e.Model.TableName() == "devices" {
refreshDeviceList()
logger.Debug.Println("restart CronWakeShutdown")
for _, job := range cronjobs.CronWakeShutdown.Entries() {
cronjobs.CronWakeShutdown.Remove(job.ID)
}
Expand Down

0 comments on commit 969d154

Please sign in to comment.