scheduler

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueueLock

type QueueLock interface {
	// LockOrPush tries to lock lockID and pushes item to queue by lockID if fails.
	// Return true if locks or false if error or item is added to queue.
	LockOrPush(ctx context.Context, lockID string, item []byte) (bool, error)
	// PopOrUnlock tries to extend lock lockID and pops item from queue by lockID.
	// It unlocks lockID if either fails.
	PopOrUnlock(ctx context.Context, lockID string, asyncUnlock bool) ([]byte, error)
	// LockAndPop tries to lock lockID and pops item from queue by lockID.
	LockAndPop(ctx context.Context, lockID string, asyncUnlock bool) ([]byte, error)
}

QueueLock interface is used to implement a lock to consistently process items for the same resource. Base implementation uses redis to set lock and store next items while current item is processing. Im-memory mutex is used to synchronize access to redis so it cannot be used in multi-instance app.

func NewQueueLock

func NewQueueLock(
	lockClient redismod.Cmdable,
	lockExpirationTime time.Duration,
	queueClient redismod.Cmdable,
	logger zerolog.Logger,
) QueueLock

NewQueueLock creates lock.

type Scheduler

type Scheduler interface {
	Start(ctx context.Context)
	Stop(ctx context.Context)
	ProcessEvent(context.Context, types.Event) error
	AckEvent(context.Context, types.Event) error
}

Scheduler ...

func NewSchedulerService

func NewSchedulerService(
	redisLockStorage redismod.UniversalClient,
	redisQueueStorage redismod.UniversalClient,
	channelPub libamqp.Channel,
	publishToQueue string,
	logger zerolog.Logger,
	lockTtl int,
	decoder encoding.Decoder,
	encoder encoding.Encoder,
) Scheduler

NewSchedulerService ...

Jump to

Keyboard shortcuts

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