looper

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

looper package provides utilities for looper job management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistributedLock

type DistributedLock interface {
	// Lock the key
	Lock(ctx context.Context, key string, expiration time.Duration) (ok bool, err error)
	// Unlock the key
	Unlock(ctx context.Context, key string) (err error)
	// Renew the key expiration time
	Renew(ctx context.Context, key string, expiration time.Duration) (err error)
}

分布式锁

type RedisLock

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

RedisLock implemented the DistributedLock interface

func NewRedisLock

func NewRedisLock(client *redis.Client) *RedisLock

func (*RedisLock) Lock

func (l *RedisLock) Lock(ctx context.Context, key string, expiration time.Duration) (ok bool, err error)

Lock the key

func (*RedisLock) Renew

func (l *RedisLock) Renew(ctx context.Context, key string, expiration time.Duration) (err error)

Renew the key expiration time

func (*RedisLock) Unlock

func (l *RedisLock) Unlock(ctx context.Context, key string) (err error)

Unlock the key

type SinglePod

type SinglePod struct {
	ErrCh chan error // 错误通道
	// contains filtered or unexported fields
}

SinglePod 单Pod执行的任务

func NewSinglePod

func NewSinglePod(id string, lock DistributedLock, run func(ctx context.Context) error, cleanup func(), conf SinglePodConfig) (*SinglePod, func(), error)

NewSinglePod 创建单Pod执行的任务

func (*SinglePod) NotifyErr

func (j *SinglePod) NotifyErr(fn func(err error))

NotifyErr 运行时错误捕获

func (*SinglePod) Start

func (j *SinglePod) Start() (err error)

Start 开始循环执行任务

type SinglePodConfig

type SinglePodConfig struct {
	Sleep        time.Duration // 任务间的休眠时间
	MaxRunTime   time.Duration // [可选,默认300s] 单次任务最大执行时间
	StandbySleep time.Duration // [可选,默认10s] 待机状态下休眠时间
}

SinglePodConfig 任务配置

Jump to

Keyboard shortcuts

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