-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlitequeue.go
More file actions
68 lines (63 loc) · 1.95 KB
/
Copy pathsqlitequeue.go
File metadata and controls
68 lines (63 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sqlitequeue
import (
"database/sql"
"time"
"github.com/goforj/queue"
"github.com/goforj/queue/driver/sqlqueuecore"
"github.com/goforj/queue/queueconfig"
_ "modernc.org/sqlite"
)
type Config struct {
queueconfig.DriverBaseConfig
DB *sql.DB
DSN string
ProcessingRecoveryGrace time.Duration
ProcessingLeaseNoTimeout time.Duration
}
// New creates a high-level Queue using the SQLite SQL backend.
// @group Constructors
//
// Example: sqlite shorthand constructor
//
// q, err := sqlitequeue.New(
// "file:queue.db?_busy_timeout=5000",
// queue.WithWorkers(4), // optional; default: 1 worker
// )
// if err != nil {
// return
// }
// _ = q
func New(dsn string, opts ...queue.Option) (*queue.Queue, error) {
return NewWithConfig(Config{DSN: dsn}, opts...)
}
// NewWithConfig creates a high-level Queue using an explicit SQLite SQL driver config.
// @group Constructors
//
// Example: sqlite config constructor
//
// q, err := sqlitequeue.NewWithConfig(
// sqlitequeue.Config{
// DriverBaseConfig: queueconfig.DriverBaseConfig{
// DefaultQueue: "critical", // default if empty: "default"
// Observer: nil, // default: nil
// },
// DB: nil, // optional; provide *sql.DB instead of DSN
// DSN: "file:queue.db?_busy_timeout=5000", // optional if DB is set
// ProcessingRecoveryGrace: 2 * time.Second, // default if <=0: 2s
// ProcessingLeaseNoTimeout: 5 * time.Minute, // default if <=0: 5m
// },
// queue.WithWorkers(4), // optional; default: 1 worker
// )
// if err != nil {
// return
// }
// _ = q
func NewWithConfig(cfg Config, opts ...queue.Option) (*queue.Queue, error) {
return sqlqueuecore.NewQueue("sqlite", sqlqueuecore.ModuleConfig{
DriverBaseConfig: cfg.DriverBaseConfig,
DB: cfg.DB,
DSN: cfg.DSN,
ProcessingRecoveryGrace: cfg.ProcessingRecoveryGrace,
ProcessingLeaseNoTimeout: cfg.ProcessingLeaseNoTimeout,
}, opts...)
}