worker

package
v0.0.0-...-e397795 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHTTPClient

func CreateHTTPClient() (*http.Client, error)

CreateHTTPClient returns a http.Client

func ExtractSizeFromFileSystem

func ExtractSizeFromFileSystem(path string) uint64

ExtractSizeFromFileSystem extracts the size from filesystem

func ExtractSizeFromLog

func ExtractSizeFromLog(logFile string, re *regexp.Regexp) uint64

ExtractSizeFromLog uses a regexp to extract the size from log files

func ExtractSizeFromRsyncLog

func ExtractSizeFromRsyncLog(logFile string) uint64

ExtractSizeFromRsyncLog extracts the size from rsync logs

func ExtractSizeFromWalk

func ExtractSizeFromWalk(path string) uint64

ExtractSizeFromWalk extracts the size from path

func FindAllSubmatchInFile

func FindAllSubmatchInFile(fileName string, re *regexp.Regexp) (matches [][][]byte, err error)

FindAllSubmatchInFile calls re.FindAllSubmatch to find matches in given file

func GetBoolEnv

func GetBoolEnv(key string) bool

func GetIntEnv

func GetIntEnv(key string, def int) int

func GetListEnv

func GetListEnv(key string) []string

func GetStringEnv

func GetStringEnv(key, def string) string

func InitLogger

func InitLogger(verbose, debug bool)

InitLogger initilizes logging format and level

func TranslateRsyncErrorCode

func TranslateRsyncErrorCode(cmdErr error) (exitCode int, msg string)

TranslateRsyncErrorCode translates the exit code of rsync to a message

Types

type Config

type Config struct {
	Name       string `toml:"name"`
	Provider   string `toml:"provider"`
	Upstream   string `toml:"upstream"`
	LogDir     string `toml:"log_dir"`
	MirrorDir  string `toml:"mirror_dir"`
	MirrorPath string `toml:"mirror_path"`
	Concurrent int    `toml:"concurrent"`
	Interval   int    `toml:"interval"`
	Retry      int    `toml:"retry"`
	Timeout    int    `toml:"timeout"`

	Command       string   `toml:"command"`
	FailOnMatch   string   `toml:"fail_on_match"`
	SizePattern   string   `toml:"size_pattern"`
	UseIPv6       bool     `toml:"use_ipv6"`
	UseIPv4       bool     `toml:"use_ipv4"`
	ExcludeFile   string   `toml:"exclude_file"`
	RsyncNoTimeo  bool     `toml:"rsync_no_timeout"`
	RsyncTimeout  int      `toml:"rsync_timeout"`
	RsyncOptions  []string `toml:"rsync_options"`
	RsyncOverride []string `toml:"rsync_override"`
	Stage1Profile string   `toml:"stage1_profile"`

	ExecOnSuccess []string `toml:"exec_on_success"`
	ExecOnFailure []string `toml:"exec_on_failure"`

	APIBase string `toml:"api_base"`
	Addr    string `toml:"listen_addr"`

	ZFSEnable bool   `toml:"zfs_enable"`
	Zpool     string `toml:"zpool"`

	BtrfsEnable  bool   `toml:"btrfs_enable"`
	SnapshotPath string `toml:"snapshot_path"`

	Verbose bool
	Debug   bool
}

Config represents worker config options

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads configuration

type Context

type Context struct {
	// contains filtered or unexported fields
}

A Context object is a layered key-value storage when enters a context, the changes to the storage would be stored in a new layer and when exits, the top layer poped and the storage returned to the state before entering this context

func NewContext

func NewContext() *Context

NewContext returns a new context object

func (*Context) Enter

func (ctx *Context) Enter() *Context

Enter generates a new layer of context

func (*Context) Exit

func (ctx *Context) Exit() (*Context, error)

Exit return the upper layer of context

func (*Context) Get

func (ctx *Context) Get(key string) (interface{}, bool)

Get returns the value corresponding to key, if it's not found in the current layer, return the lower layer context's value

func (*Context) Set

func (ctx *Context) Set(key string, value interface{})

Set sets the value to the key at current layer

type MemBytes

type MemBytes int64

func (*MemBytes) Set

func (m *MemBytes) Set(value string) error

Set sets the value of the MemBytes by passing a string

func (*MemBytes) Type

func (m *MemBytes) Type() string

Type returns the type

func (*MemBytes) UnmarshalText

func (m *MemBytes) UnmarshalText(s []byte) error

UnmarshalText is the customized unmarshaler for MemBytes

func (*MemBytes) Value

func (m *MemBytes) Value() int64

Value returns the value in int64

type Worker

type Worker struct {
	L sync.Mutex
	// contains filtered or unexported fields
}

A Worker is an instance of tunasync worker

func NewTUNASyncWorker

func NewTUNASyncWorker(cfg *Config) *Worker

NewTUNASyncWorker creates a worker

func (*Worker) GetJSON

func (w *Worker) GetJSON(url string, obj interface{}) (*http.Response, error)

GetJSON gets a json response from url

func (*Worker) Halt

func (w *Worker) Halt()

Halt stops all jobs

func (*Worker) HandleRequest

func (w *Worker) HandleRequest(method, url string, obj interface{}) (*http.Response, error)

HandleRequest post/head url

func (*Worker) Name

func (w *Worker) Name() string

Name returns worker name

func (*Worker) Run

func (w *Worker) Run()

Run runs worker forever

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL