utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: BSD-3-Clause Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

func Abs64

func Abs64(n int64) int64

func AssignWorkers

func AssignWorkers(nodeCount, workerCount, limit int) []int

AssignWorkers assigns workers between nodes and limit maximum per node.

limit = 0 indicates no limit at all

func CanSchedule

func CanSchedule(ipList []string, hostname, ip string) bool

CanSchedule returns whether current scheduler can join into the specified strategy (based on its iplist)

ipList is the range that can be scheduled on including hostnames and ip addresses
hostname indicates current node's hostname
ip indicates current node's ip address

func ContainsTaskItem

func ContainsTaskItem(arr []definition.TaskItem, itemId string) bool

ContainsTaskItem returns whether specific itemId existed in slice

func ContextDone added in v1.0.0

func ContextDone(ctx context.Context) bool

ContextDone returns true if the given context is done

func CronDelay

func CronDelay(begin cron.Schedule, end cron.Schedule) time.Duration

CronDelay add suitable delay according to cron settings

	when only beginning is set:
 -----------b-------------b-------------b-------------
   |------->|
	when both beginning and ending are set:
	b=====e------b=====e--------b=====e--------b=====e---
	   |==|
	         |-->|=====|        |=====|        |=====|

func DelayContext added in v1.0.0

func DelayContext(ctx context.Context, duration time.Duration) bool

DelayContext try to wait and return true if normally completed.

func Dereference

func Dereference(v interface{}) interface{}

Dereference returns the value relied behind the given pointer

func FetchLeader

func FetchLeader(uuids []string) string

FetchLeader returns the uuid of leader in the array

func GenerateUUID

func GenerateUUID(sequence uint64) string

func GenerateUUIDPrefix

func GenerateUUIDPrefix() string

GenerateUUIDPrefix is used to generate the prefix of uuid

func GetHostIPv4

func GetHostIPv4() string

GetHostIPv4 returns localhost's ip in ipv4. If failed return "127.0.0.1" It's suggested that the hostname is resolved to the correct address.

func GetHostName

func GetHostName() string

GetHostName returns localhost's hostname. Return "localhost" for fallback

func IsLeader

func IsLeader(uuids []string, uuid string) bool

IsLeader tells whether specified uuid is the leader in the uuid slice

func LoopContext added in v1.0.0

func LoopContext(ctx context.Context, interval time.Duration, loopFn, cleanupFn func())

LoopContext is used to execute a func with fixed interval.

The cleanupFn will be invoked when the loop ends

func Max

func Max(i, j int) int

func Max64

func Max64(i, j int64) int64

func Min

func Min(i, j int) int

func Min64

func Min64(i, j int64) int64

func OwnSign

func OwnSign(strategyId string) string

OwnSign gets ownsign from strategyId, "" for no ownsign

func ParseStrategyCron

func ParseStrategyCron(strategy *definition.Strategy) (cron.Schedule, cron.Schedule)

ParseStrategyCron parse cron expressions of begin and end from given strategy

func RemoveTaskItem

func RemoveTaskItem(arr []definition.TaskItem, itemId string) []definition.TaskItem

RemoveTaskItem remove specific task item from slice

func SortRuntimesWithShuffle

func SortRuntimesWithShuffle(runtimes []*definition.StrategyRuntime)

SortRuntimes sort the runtimes based on requestedNum in descending order

A shuffle will be made between same num for better ditribution of workers

func SortSchedulers

func SortSchedulers(schedulers []*definition.Scheduler)

func SortStrategyRuntimes

func SortStrategyRuntimes(strategyRuntimes []*definition.StrategyRuntime)

func SortTaskAssignments

func SortTaskAssignments(TaskAssignments []*definition.TaskAssignment)

func SortTaskRuntimes

func SortTaskRuntimes(taskRuntimes []*definition.TaskRuntime)

func TypeName

func TypeName(obj interface{}) string

TypeName returns the "correct" name of type for specified value

Types

type TraceData added in v1.1.1

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

func StackTraceData added in v1.1.1

func StackTraceData() *TraceData

func (*TraceData) Data added in v1.1.1

func (data *TraceData) Data() []byte

func (*TraceData) Len added in v1.1.1

func (data *TraceData) Len() int

func (*TraceData) Recycle added in v1.1.1

func (data *TraceData) Recycle()

call this to reuse the memory

func (*TraceData) String added in v1.1.1

func (data *TraceData) String() string

Jump to

Keyboard shortcuts

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