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 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
|
|
|
|
}
|
|
|
|
|
2023-07-11 10:36:56 +02:00
|
|
|
_, err = s.Every(viper.GetString("mastodon.postinterval")).WaitForSchedule().Do(RunSingleQueueItem)
|
2023-07-04 16:56:09 +02:00
|
|
|
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
|
|
|
}
|