ed330fa6be
commitf5baab4e88
Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 17:50:53 2022 -0400 Finalize activity event sending logic and cron config commit9830387f21
Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 16:26:13 2022 -0400 Send power events in a more usable format commit49f3a61d16
Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 15:47:24 2022 -0400 Configure cron to actually send to endpoint commit28137c4c14
Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 15:42:29 2022 -0400 Copy the body buffer otherwise subsequent backoff attempts will not have a buffer to send commit20e44bdc55
Author: DaneEveritt <dane@daneeveritt.com> Date: Sat Jul 9 14:38:41 2022 -0400 Add internal logic to process activity events and send them to the panel commit0380488cd2
Author: DaneEveritt <dane@daneeveritt.com> Date: Mon Jul 4 17:55:17 2022 -0400 Track power events commit9eab08b92f
Author: DaneEveritt <dane@daneeveritt.com> Date: Mon Jul 4 17:36:03 2022 -0400 Initial logic to support logging activity on Wings to send back to the panel
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package cron
|
|
|
|
import (
|
|
"emperror.dev/errors"
|
|
"github.com/apex/log"
|
|
"github.com/go-co-op/gocron"
|
|
"github.com/pterodactyl/wings/config"
|
|
"github.com/pterodactyl/wings/server"
|
|
"github.com/pterodactyl/wings/system"
|
|
"time"
|
|
)
|
|
|
|
var o system.AtomicBool
|
|
|
|
// Scheduler configures the internal cronjob system for Wings and returns the scheduler
|
|
// instance to the caller. This should only be called once per application lifecycle, additional
|
|
// calls will result in an error being returned.
|
|
func Scheduler(m *server.Manager) (*gocron.Scheduler, error) {
|
|
if o.Load() {
|
|
return nil, errors.New("cron: cannot call scheduler more than once in application lifecycle")
|
|
}
|
|
o.Store(true)
|
|
l, err := time.LoadLocation(config.Get().System.Timezone)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "cron: failed to parse configured system timezone")
|
|
}
|
|
|
|
s := gocron.NewScheduler(l)
|
|
_, _ = s.Tag("activity").Every(config.Get().System.ActivitySendInterval).Seconds().Do(func() {
|
|
if err := processActivityLogs(m, config.Get().System.ActivitySendCount); err != nil {
|
|
log.WithField("error", err).Error("cron: failed to process activity events")
|
|
}
|
|
})
|
|
|
|
return s, nil
|
|
}
|