common

package
v0.0.0-...-3f08e25 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ETCD_JOBS_CATEGORY_DIR = "/crontab/categories/" // 计划任务的分类
View Source
const ETCD_JOBS_DIR = "/crontab/jobs/"
View Source
const ETCD_JOBS_LOCK_DIR = "/crontab/lock/"
View Source
const ETCD_JOB_KILL_DIR = "/crontab/kill/"
View Source
const ETCD_WORKER_DIR = "/crontab/workers/"

ETCD相关变量

View Source
const JOB_EVENT_DELETE = 1 // Job Delete事件
View Source
const JOB_EVENT_KILL = 2 // Job Kill事件
View Source
const JOB_EVENT_PUT = 0 // Job PUT事件
View Source
const SocketMessageHeader = "www.codelieche.com" // Socket发送数据包的头部

Variables

View Source
var (
	LOCK_IS_USING = errors.New("lock is using")
)
View Source
var NOT_FOUND = fmt.Errorf("404 not found")

错误类

View Source
var NotFountError = fmt.Errorf("404 not fount")
View Source
var SocketDataLength int = 4 // 32位
View Source
var SocketHeaderLength = len([]byte(SocketMessageHeader)) // Socket发送消息

Functions

func BinaryToInt

func BinaryToInt(data []byte) (n int)

对数据包解包:消息的长度

func BuildJobExecuteInfo

func BuildJobExecuteInfo(jobPlan *datamodels.JobSchedulePlan) (jobExecuteInfo *datamodels.JobExecuteInfo)

构造执行状态信息

func BuildJobSchedulePlan

func BuildJobSchedulePlan(job *datamodels.JobEtcd) (jobSchedulePlan *datamodels.JobSchedulePlan, err error)

构建job执行计划

func GenerateName

func GenerateName() (string, error)

随机生成个名字 创建job,未传入name的时候会调用它

func GetFirstLocalIpAddress

func GetFirstLocalIpAddress() (ipv4 string, err error)

获取本机的第一个网卡IP地址

func PacketData

func PacketData(message []byte) []byte

对要发送的数据打包 打包数据:Header + len(message) + message

func PacketInterfaceData

func PacketInterfaceData(object interface{}) (data []byte)

func ParseConfig

func ParseConfig() (err error)

func UnPacketData

func UnPacketData(data []byte, c chan<- []byte) []byte

对数据包解封装

func UnpackByteToJob

func UnpackByteToJob(value []byte) (job *datamodels.JobEtcd, err error)

反序列化Job

Types

type Config

type Config struct {
	Master *MasterConfig  `json:"master" yaml:"master"`
	Worker *WorkerConfig  `json:"worker" yaml:"worker"`
	MySQL  *MySQLDatabase `json:"mysql" yaml:"mysql"`
	Redis  *RedisDatabase `json:"redis" yaml:"redis"`
	Etcd   *EtcdConfig    `json:"etcd" yaml:"etcd"`
	Mongo  *MongoConfig   `json:"mongo" yaml:"mongo"`
	Debug  bool           `json:"debug" yaml:"debug"`
}

Master Worker相关的配置

func GetConfig

func GetConfig() *Config

获取配置

type EtcdConfig

type EtcdConfig struct {
	Endpoints []string       `json:"endpoints", yaml:"endpoints"`
	Timeout   int            `json:"timeout"` // etcd操作的超时时间 秒
	TLS       *EtcdTLSConfig `json:"tls", yaml:"tls"`
}

master etcd的相关配置

type EtcdTLSConfig

type EtcdTLSConfig struct {
	CertFile string `json:"cert_file",yaml:"certfile"`
	KeyFile  string `json:"key_file", yaml:"keyfile"`
	CaFile   string `json:"ca_file", yaml:"cafile"`
}

type HttpConfig

type HttpConfig struct {
	Host    string `json:"host", yaml:"host"`
	Port    int    `json:"port", yaml: "port"`
	Timeout int    `json:"timeout", yaml: "timeout"` // 超时时间 毫秒
}

http Web相关的配置

type JobLock

type JobLock struct {
	IsLocked     bool      // 释放上锁成功,也可根据leaseId是否不为0判断
	NeedKillChan chan bool // 是否需要杀掉jobLock对应的job程序: 正常退出的请传递个false
	// contains filtered or unexported fields
}

分布式锁

func NewJobLock

func NewJobLock(name string, kv clientv3.KV, lease clientv3.Lease) (jobLock *JobLock)

初始化一把锁

func (*JobLock) TryLock

func (jobLock *JobLock) TryLock() (err error)

尝试上锁

func (*JobLock) Unlock

func (jobLock *JobLock) Unlock()

type MasterConfig

type MasterConfig struct {
	Http *HttpConfig `json:"http" yaml:"http"`
}

master相关的配置

type MongoConfig

type MongoConfig struct {
	Hosts    []string `json:"hosts" yaml:"hosts"`       // 主机列表
	User     string   `json:"user" yaml:"user"`         // 用户名
	Password string   `json:"password" yaml:"password"` // MongoDB的用户密码
	Database string   `json:"database" yaml:"database"` // 数据库的名字
}

master mongodb config

type MySQLDatabase

type MySQLDatabase struct {
	Host     string `json:"host" yaml:"host"`         // 数据库地址
	Port     int    `json:"port" yaml:"port"`         // 端口号
	User     string `json:"user" yaml:"user"`         // 用户
	Password string `json:"password" yaml:"password"` // 用户密码
	Database string `json:"database" yaml:"database"` // 数据库
}

MySQL数据库相关配置

type RedisDatabase

type RedisDatabase struct {
	Host     string   `json:"host" yaml:"host"`         // redis主机,不填会是默认的127.0.0.1:6739
	Clusters []string `json:"clusters" yaml:"clusters"` // Redis集群地址
	Password string   `json:"password" yaml:"password"` // redis的密码
	DB       int      `json:"db" yaml:db`               // 哪个库
}

Redis配置

type WorkerConfig

type WorkerConfig struct {
	Http       *HttpConfig     `json:"http" yaml:"http"`
	MasterUrl  string          `json:"master_url" yaml:"master_url"`
	Categories map[string]bool `json:"categories" yaml: "categories"`
}

worker相关的配置

func (*WorkerConfig) GetSocketUrl

func (workerConfig *WorkerConfig) GetSocketUrl() (socketUrl string, err error)

获取socket的连接地址

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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