<commit_before>package summer

import (
	"github.com/cocotyty/tdc"
	"log"
	"os"
	"os/signal"
	"reflect"
	"time"
)

var DefaultBasket = NewBasket()

func init() {
	PluginRegister(&ProviderPlugin{}, AfterInit)
	PluginRegister(&FieldReferencePlugin{}, AfterInit)
}

func TomlFile(path string) error {
	plugin, err := NewTomlPluginByFilePath(path)
	if err != nil {
		return err
	}
	PluginRegister(plugin, BeforeInit)
	return nil
}
func DynamicTomlFile(path string, solver tdc.ResourceSolver, listener tdc.Listener) error {
	src, err := tdc.NewDynamicToml(solver, listener).Load(path)
	if err != nil {
		return err
	}
	return Toml(string(src))
}

var FailFastConfigEnvMode = "mode"

func FailFastConfig(path string, resolverAddr string) {
	err := DynamicTomlFile(path, tdc.NewHTTPResourceSolver(resolverAddr, os.Getenv(FailFastConfigEnvMode), time.Second), func(name string, data []byte, version uint64, exist bool) {
		ShutDown()
	})
	if err != nil {
		panic(err)
	}
}
func Toml(src string) error {
	plugin, err := NewTomlPluginBySource(src)
	if err != nil {
		return err
	}
	PluginRegister(plugin, BeforeInit)
	return nil
}

func AddNotStrict(name string, stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.AddNotStrict(name, stone, nil)
	} else {
		DefaultBasket.AddNotStrict(name, stone, value[0])
	}
}
func PutNotStrict(stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.PutNotStrict(stone, nil)
	} else {
		DefaultBasket.PutNotStrict(stone, value[0])
	}
}

// add a stone to the default basket with a name
func Add(name string, stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.Add(name, stone)
	} else {
		DefaultBasket.AddWithValue(name, stone, value[0], false)
	}
}

// put a stone into the default basket
func Put(stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.Put(stone)
	} else {
		DefaultBasket.PutWithValue(stone, value[0], false)
	}
}

// get a stone with the name and the type
func GetStone(name string, t reflect.Type) (stone Stone) {
	return DefaultBasket.GetStone(name, t)
}

// get a tone with the name
func GetStoneWithName(name string) (stone Stone) {
	return DefaultBasket.GetStoneWithName(name)
}

func GetStoneByType(typ interface{}) (stone Stone) {
	return DefaultBasket.GetStoneByType(typ)
}

// register a plugin to basket
func PluginRegister(p Plugin, pt PluginWorkTime) {
	DefaultBasket.PluginRegister(p, pt)
}

// just start
func Start() {
	DefaultBasket.Start()
}

// start and wait interrupt signal to shutdown
func Work() {
	DefaultBasket.Start()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			log.Println("SHUTDOWN:", sig)
			DefaultBasket.ShutDown()
			os.Exit(0)
		}
	}()
}
func Strict() {
	DefaultBasket.Strict()
}
func ShutDown() {
	DefaultBasket.ShutDown()
}
<commit_msg>if dynamic config changed  sleep  rand(0-30) seconds<commit_after>package summer

import (
	"github.com/cocotyty/tdc"
	"log"
	"math/rand"
	"os"
	"os/signal"
	"reflect"
	"time"
)

var DefaultBasket = NewBasket()

func init() {
	PluginRegister(&ProviderPlugin{}, AfterInit)
	PluginRegister(&FieldReferencePlugin{}, AfterInit)
}

func TomlFile(path string) error {
	plugin, err := NewTomlPluginByFilePath(path)
	if err != nil {
		return err
	}
	PluginRegister(plugin, BeforeInit)
	return nil
}
func DynamicTomlFile(path string, solver tdc.ResourceSolver, listener tdc.Listener) error {
	src, err := tdc.NewDynamicToml(solver, listener).Load(path)
	if err != nil {
		return err
	}
	return Toml(string(src))
}

var FailFastConfigEnvMode = "mode"
var rd = rand.New(rand.NewSource(time.Now().UnixNano()))

func FailFastConfig(path string, resolverAddr string) {
	err := DynamicTomlFile(
		path,
		tdc.NewHTTPResourceSolver(resolverAddr, os.Getenv(FailFastConfigEnvMode), time.Second),
		func(name string, data []byte, version uint64, exist bool) {
			time.Sleep(time.Millisecond * time.Duration(rd.Int63n(30*1000)))
			ShutDown()
			os.Exit(0)
		})
	if err != nil {
		panic(err)
	}
}
func Toml(src string) error {
	plugin, err := NewTomlPluginBySource(src)
	if err != nil {
		return err
	}
	PluginRegister(plugin, BeforeInit)
	return nil
}

func AddNotStrict(name string, stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.AddNotStrict(name, stone, nil)
	} else {
		DefaultBasket.AddNotStrict(name, stone, value[0])
	}
}
func PutNotStrict(stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.PutNotStrict(stone, nil)
	} else {
		DefaultBasket.PutNotStrict(stone, value[0])
	}
}

// add a stone to the default basket with a name
func Add(name string, stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.Add(name, stone)
	} else {
		DefaultBasket.AddWithValue(name, stone, value[0], false)
	}
}

// put a stone into the default basket
func Put(stone Stone, value ...interface{}) {
	if len(value) == 0 {
		DefaultBasket.Put(stone)
	} else {
		DefaultBasket.PutWithValue(stone, value[0], false)
	}
}

// get a stone with the name and the type
func GetStone(name string, t reflect.Type) (stone Stone) {
	return DefaultBasket.GetStone(name, t)
}

// get a tone with the name
func GetStoneWithName(name string) (stone Stone) {
	return DefaultBasket.GetStoneWithName(name)
}

func GetStoneByType(typ interface{}) (stone Stone) {
	return DefaultBasket.GetStoneByType(typ)
}

// register a plugin to basket
func PluginRegister(p Plugin, pt PluginWorkTime) {
	DefaultBasket.PluginRegister(p, pt)
}

// just start
func Start() {
	DefaultBasket.Start()
}

// start and wait interrupt signal to shutdown
func Work() {
	DefaultBasket.Start()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			log.Println("SHUTDOWN:", sig)
			DefaultBasket.ShutDown()
			os.Exit(0)
		}
	}()
}
func Strict() {
	DefaultBasket.Strict()
}
func ShutDown() {
	DefaultBasket.ShutDown()
}

{'fraction_non_alphanumeric': 0.13171225937183384, 'fraction_numerical': 0.0060790273556231, 'mean_word_length': 4.530345471521942, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1712706', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2087, 'n_words': 534}