utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: BSD-3-Clause Imports: 13 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 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 Delay

func Delay(target DelaySupport, duration time.Duration)

delay guarantees an imprecision delay function

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 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 DelaySupport

type DelaySupport interface {
	NeedStop() bool
}

Jump to

Keyboard shortcuts

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