2023-07-03 15:30:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 Laura Kalb <dev@lauka.net>
|
|
|
|
* The code of this project is available under the MIT license. See the LICENSE file for more info.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2023-07-04 16:56:09 +02:00
|
|
|
"github.com/go-co-op/gocron"
|
|
|
|
"github.com/rs/zerolog/log"
|
2023-07-03 15:30:14 +02:00
|
|
|
"github.com/spf13/cobra"
|
2023-07-04 16:56:09 +02:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"time"
|
2023-07-03 15:30:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func RunRoot(cmd *cobra.Command, args []string) {
|
2023-07-04 16:56:09 +02:00
|
|
|
UpdateBundles()
|
2023-07-03 15:30:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func RunDaemon(cmd *cobra.Command, args []string) {
|
2023-07-04 16:56:09 +02:00
|
|
|
StartCronJobs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func StartCronJobs() {
|
|
|
|
s := gocron.NewScheduler(time.UTC)
|
|
|
|
|
|
|
|
_, err := s.Every(viper.GetString("humblebundle.pollinterval")).Do(UpdateBundles)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Str("func", "StartCronJobs").Str("job", "UpdateBundlesJob").
|
|
|
|
Msgf("Scheduler Error: %q", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = s.Every(viper.GetString("mastodon.postinterval")).Do(RunSingleQueueItem)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Str("func", "StartCronJobs").Str("job", "RunSingleQueueItem").
|
|
|
|
Msgf("Scheduler Error: %q", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.StartBlocking()
|
2023-07-03 15:30:14 +02:00
|
|
|
}
|