)
const (
// TODO make MemBackend queue capacity configurable
defaultMemQueueCapacity = 10000 // the default capacity of individual queues
emptyCapacity = 0
)
// MemBackend is a memory-backed neoq backend
type MemBackend struct {
cancelFuncs []context.CancelFunc // A collection of cancel functions to be called upon Shutdown()
cron *cron.Cron
logger Logger
jobCheckInterval time.Duration // the duration of time between checking for future jobs to schedule
mu *sync.Mutex // mutext to protect mutating state on a pgWorker
jobCount int64 // number of jobs that have been queued since start
handlers sync.Map // map queue names [string] to queue handlers [Handler]
fingerprints sync.Map // map fingerprints [string] to their jobs [Job]
futureJobs sync.Map // map jobIDs [int64] to [Jobs]
queues sync.Map // map queue names [string] to queue handler channels [chan Job]
}
func NewMemBackend(opts ...ConfigOption) (n Neoq, err error) {
mb := &MemBackend{
cron: cron.New(),
mu: &sync.Mutex{},
queues: sync.Map{},
handlers: sync.Map{},
futureJobs: sync.Map{},
fingerprints: sync.Map{},
logger: slog.New(slog.NewTextHandler(os.Stdout)),
jobCount: 0,
cancelFuncs: []context.CancelFunc{},
jobCheckInterval: DefaultJobCheckInterval,
}
mb.cron.Start()
defaultMemQueueCapacity = 10000 // the default capacity of individual queues
jobCount int64 // number of jobs that have been queued since start
handlers sync.Map // map queue names [string] to queue handlers [Handler]
fingerprints sync.Map // map fingerprints [string] to their jobs [Job]
futureJobs sync.Map // map jobIDs [int64] to [Jobs]
queues sync.Map // map queue names [string] to queue handler channels [chan Job]
cancelFuncs []context.CancelFunc // A collection of cancel functions to be called upon Shutdown()
mu *sync.Mutex // mutext to protect mutating state on a pgWorker
jobCount int64 // number of jobs that have been queued since start
handlers sync.Map // map queue names [string] to queue handlers [Handler]
fingerprints sync.Map // map fingerprints [string] to their jobs [Job]
futureJobs sync.Map // map jobIDs [int64] to [Jobs]
queues sync.Map // map queue names [string] to queue handler channels [chan Job]
https://github.com/acaloiaro/neoq/blob/895ea02a26406d7f530bdeadbeeb799657df9459/memory_backend.go#L19