workitemLock

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: BSD-3-Clause Imports: 10 Imported by: 3

Documentation

Overview

Package workitemLock provides a locking mechanism for workitems

Index

Constants

This section is empty.

Variables

View Source
var LockTypeName = map[int]string{
	0: "memory",
	1: "mongodb",
}

Functions

This section is empty.

Types

type MemoryWorkItemLock

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

MemoryWorkItemLock is a simple in-memory implementation of the WorkItemLock interface. Cannot be used for horizontal scaling.

func NewMemoryWorkItemLock

func NewMemoryWorkItemLock() *MemoryWorkItemLock

func (*MemoryWorkItemLock) Lock

func (w *MemoryWorkItemLock) Lock(_ context.Context, workitemID string, ttl *time.Duration) error

func (*MemoryWorkItemLock) StartHousekeeping

func (w *MemoryWorkItemLock) StartHousekeeping()

func (*MemoryWorkItemLock) Unlock

func (w *MemoryWorkItemLock) Unlock(_ context.Context, workitemID string) error

type MongoWorkItemLock

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

MongoWorkItemLock is a workitem lock implementation based on MongoDB

func NewMongoWorkItemLock

func NewMongoWorkItemLock(lockName, lockID string, db *mongo.Database) *MongoWorkItemLock

func (*MongoWorkItemLock) Lock

func (w *MongoWorkItemLock) Lock(ctx context.Context, workitemID string, ttl *time.Duration) error

Lock locks a workitem for the initialized lockID

func (*MongoWorkItemLock) StartHousekeeping

func (w *MongoWorkItemLock) StartHousekeeping()

StartHousekeeping starts a housekeeping goroutine which removes expired locks

func (*MongoWorkItemLock) Unlock

func (w *MongoWorkItemLock) Unlock(ctx context.Context, workitemID string) error

Unlock removes the lock for the workitem

type WorkItemLock

type WorkItemLock interface {
	Lock(ctx context.Context, workitemID string, ttl *time.Duration) error
	Unlock(ctx context.Context, workitemID string) error
}

WorkItemLock allows the unwindia services to lock workitems to prevent concurrent processing

type WorkItemLockEntry

type WorkItemLockEntry struct {
	ID        string     `json:"id,omitempty" bson:"_id,omitempty"`
	LockedBy  string     `json:"lockedBy" bson:"lockedBy"`
	CreatedAt time.Time  `json:"createdAt" bson:"createdAt"`
	ExpiresAt *time.Time `json:"expiresAt" bson:"expiresAt"`
}

type WorkItemLockType

type WorkItemLockType int
const (
	LOCK_MEMORY WorkItemLockType = iota
	LOCK_MONGODB
)

func (WorkItemLockType) String

func (p WorkItemLockType) String() string

func (*WorkItemLockType) Unmarshal

func (p *WorkItemLockType) Unmarshal(data string) error

func (*WorkItemLockType) UnmarshalJSON

func (p *WorkItemLockType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals b into PulsarAuth.

func (*WorkItemLockType) UnmarshalText

func (p *WorkItemLockType) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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