<commit_before>package cmd

import (
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/genzj/goTApaper/api"
	"github.com/genzj/goTApaper/config"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var daemonCmd = &cobra.Command{
	Use:   "daemon",
	Short: "Refresh and set desktop periodically",
	Long:  `Refresh and set desktop periodically`,
	Run: func(cmd *cobra.Command, args []string) {
		daemon()
	},
}

func init() {
	daemonCmd.PersistentFlags().Uint32P("interval", "i", config.DefaultDaemonInterval, "interval between two refreshes")
	viper.BindPFlag("daemon.interval", daemonCmd.PersistentFlags().Lookup("interval"))
	RootCmd.AddCommand(daemonCmd)
}

func daemon() {
	api.StartApiServer()
	ch := make(chan int)

	config.Observe("*", func(key string, old, new interface{}) {
		logrus.WithField("key", key).WithField("old", old).WithField("new", new).Debug("config change triggers refresh")
		ch <- 1
	})

	for {
		refresh()
		interval := viper.GetInt("daemon.interval")
		logrus.WithField("interval", interval).Debug("refresh over, going to sleep")
		select {
		case <-time.After(time.Duration(interval) * time.Second):
			logrus.WithField("interval", interval).Debug("awake from sleep")
		case <-ch:
			logrus.Debug("triggered by config observer")
		}
	}
}
<commit_msg>disable api server on master branch<commit_after>package cmd

import (
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/genzj/goTApaper/config"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var daemonCmd = &cobra.Command{
	Use:   "daemon",
	Short: "Refresh and set desktop periodically",
	Long:  `Refresh and set desktop periodically`,
	Run: func(cmd *cobra.Command, args []string) {
		daemon()
	},
}

func init() {
	daemonCmd.PersistentFlags().Uint32P("interval", "i", config.DefaultDaemonInterval, "interval between two refreshes")
	viper.BindPFlag("daemon.interval", daemonCmd.PersistentFlags().Lookup("interval"))
	RootCmd.AddCommand(daemonCmd)
}

func daemon() {
	//api.StartApiServer()
	ch := make(chan int)

	config.Observe("*", func(key string, old, new interface{}) {
		logrus.WithField("key", key).WithField("old", old).WithField("new", new).Debug("config change triggers refresh")
		ch <- 1
	})

	for {
		refresh()
		interval := viper.GetInt("daemon.interval")
		logrus.WithField("interval", interval).Debug("refresh over, going to sleep")
		select {
		case <-time.After(time.Duration(interval) * time.Second):
			logrus.WithField("interval", interval).Debug("awake from sleep")
		case <-ch:
			logrus.Debug("triggered by config observer")
		}
	}
}

{'fraction_non_alphanumeric': 0.1620986687548943, 'fraction_numerical': 0.00548159749412686, 'mean_word_length': 5.025943396226415, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2168223', 'n_tokens_mistral': 949, 'n_tokens_neox': 891, 'n_words': 182}