mirror of
https://github.com/acaloiaro/neoq
synced 2026-07-21 18:29:08 +00:00
43 lines
861 B
Go
43 lines
861 B
Go
//go:build testing
|
|
|
|
package memory
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/acaloiaro/neoq"
|
|
"github.com/acaloiaro/neoq/logging"
|
|
"github.com/robfig/cron"
|
|
)
|
|
|
|
// TestingBackend initializes a backend for testing purposes
|
|
func TestingBackend(conf *neoq.Config,
|
|
c *cron.Cron,
|
|
queues, h, futureJobs, fingerprints *sync.Map,
|
|
logger logging.Logger,
|
|
) neoq.BackendInitializer {
|
|
return func(ctx context.Context, opts ...neoq.ConfigOption) (backend neoq.Neoq, err error) {
|
|
mb := &MemBackend{
|
|
config: conf,
|
|
cron: c,
|
|
mu: &sync.Mutex{},
|
|
queues: queues,
|
|
handlers: h,
|
|
futureJobs: futureJobs,
|
|
fingerprints: fingerprints,
|
|
logger: logger,
|
|
jobCount: 0,
|
|
cancelFuncs: []context.CancelFunc{},
|
|
}
|
|
mb.cron.Start()
|
|
|
|
for _, opt := range opts {
|
|
opt(mb.config)
|
|
}
|
|
|
|
backend = mb
|
|
|
|
return
|
|
}
|
|
}
|