mirror of
https://github.com/acaloiaro/neoq
synced 2026-07-21 18:29:08 +00:00
Move config.WithConnectionString -> postgres.WithConnectionString (#43)
This commit is contained in:
parent
ba0032eaba
commit
219ea84d76
8 changed files with 19 additions and 25 deletions
|
|
@ -78,7 +78,7 @@ nq.Enqueue(ctx, &jobs.Job{
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
nq, _ := neoq.New(ctx,
|
nq, _ := neoq.New(ctx,
|
||||||
neoq.WithBackend(postgres.Backend),
|
neoq.WithBackend(postgres.Backend),
|
||||||
config.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"),
|
postgres.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"),
|
||||||
)
|
)
|
||||||
|
|
||||||
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) {
|
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) {
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ type PgBackend struct {
|
||||||
//
|
//
|
||||||
// If the database does not yet exist, Neoq will attempt to create the database and related tables by default.
|
// If the database does not yet exist, Neoq will attempt to create the database and related tables by default.
|
||||||
//
|
//
|
||||||
// Backend requires that one of the [config.ConfigOption] is [config.WithConnectionString]
|
// Backend requires that one of the [config.ConfigOption] is [WithConnectionString]
|
||||||
//
|
//
|
||||||
// Connection strings may be a URL or DSN-style connection strings. The connection string supports multiple
|
// Connection strings may be a URL or DSN-style connection strings. The connection string supports multiple
|
||||||
// options detailed below.
|
// options detailed below.
|
||||||
|
|
@ -158,6 +158,13 @@ func Backend(ctx context.Context, opts ...config.Option) (pb types.Backend, err
|
||||||
return pb, nil
|
return pb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithConnectionString configures neoq postgres backend to use the specified connection string when connecting to a backend
|
||||||
|
func WithConnectionString(connectionString string) config.Option {
|
||||||
|
return func(c *config.Config) {
|
||||||
|
c.ConnectionString = connectionString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithTransactionTimeout sets the time that PgBackend's transactions may be idle before its underlying connection is
|
// WithTransactionTimeout sets the time that PgBackend's transactions may be idle before its underlying connection is
|
||||||
// closed
|
// closed
|
||||||
// The timeout is the number of milliseconds that a transaction may sit idle before postgres terminates the
|
// The timeout is the number of milliseconds that a transaction may sit idle before postgres terminates the
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/acaloiaro/neoq"
|
"github.com/acaloiaro/neoq"
|
||||||
"github.com/acaloiaro/neoq/backends/postgres"
|
"github.com/acaloiaro/neoq/backends/postgres"
|
||||||
"github.com/acaloiaro/neoq/config"
|
|
||||||
"github.com/acaloiaro/neoq/handler"
|
"github.com/acaloiaro/neoq/handler"
|
||||||
"github.com/acaloiaro/neoq/internal"
|
"github.com/acaloiaro/neoq/internal"
|
||||||
"github.com/acaloiaro/neoq/jobs"
|
"github.com/acaloiaro/neoq/jobs"
|
||||||
|
|
@ -34,7 +33,7 @@ func TestBasicJobProcessing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), config.WithConnectionString(connString))
|
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString(connString))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +86,7 @@ func TestBasicJobMultipleQueue(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), config.WithConnectionString(connString))
|
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString(connString))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +162,7 @@ func TestCron(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), config.WithConnectionString(connString))
|
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString(connString))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,8 @@ const (
|
||||||
// schdule the job for execution.
|
// schdule the job for execution.
|
||||||
// E.g. right now is 16:00 and a job's RunAfter is 16:30 of the same date. This job will get a dedicated goroutine to
|
// E.g. right now is 16:00 and a job's RunAfter is 16:30 of the same date. This job will get a dedicated goroutine to
|
||||||
// wait until the job's RunAfter, scheduling the job to be run exactly at RunAfter
|
// wait until the job's RunAfter, scheduling the job to be run exactly at RunAfter
|
||||||
DefaultFutureJobWindow = 30 * time.Second
|
DefaultFutureJobWindow = 30 * time.Second
|
||||||
DefaultJobCheckInterval = 5 * time.Second
|
DefaultJobCheckInterval = 5 * time.Second
|
||||||
DefaultTransactionTimeout = time.Minute
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
@ -38,12 +37,5 @@ func New() *Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithConnectionString configures neoq to use the specified connection string when connecting to a backend
|
|
||||||
func WithConnectionString(connectionString string) Option {
|
|
||||||
return func(c *Config) {
|
|
||||||
c.ConnectionString = connectionString
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BackendInitializer is a function that initializes a backend
|
// BackendInitializer is a function that initializes a backend
|
||||||
type BackendInitializer func(ctx context.Context, opts ...Option) (backend types.Backend, err error)
|
type BackendInitializer func(ctx context.Context, opts ...Option) (backend types.Backend, err error)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"github.com/acaloiaro/neoq"
|
"github.com/acaloiaro/neoq"
|
||||||
"github.com/acaloiaro/neoq/backends/postgres"
|
"github.com/acaloiaro/neoq/backends/postgres"
|
||||||
"github.com/acaloiaro/neoq/config"
|
|
||||||
"github.com/acaloiaro/neoq/jobs"
|
"github.com/acaloiaro/neoq/jobs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -15,8 +14,8 @@ func main() {
|
||||||
const queue = "foobar"
|
const queue = "foobar"
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
nq, err := neoq.New(ctx,
|
nq, err := neoq.New(ctx,
|
||||||
config.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"),
|
|
||||||
neoq.WithBackend(postgres.Backend),
|
neoq.WithBackend(postgres.Backend),
|
||||||
|
postgres.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"),
|
||||||
postgres.WithTransactionTimeout(1000), // nolint: mnd, gomnd
|
postgres.WithTransactionTimeout(1000), // nolint: mnd, gomnd
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"github.com/acaloiaro/neoq"
|
"github.com/acaloiaro/neoq"
|
||||||
"github.com/acaloiaro/neoq/backends/postgres"
|
"github.com/acaloiaro/neoq/backends/postgres"
|
||||||
"github.com/acaloiaro/neoq/config"
|
|
||||||
"github.com/acaloiaro/neoq/handler"
|
"github.com/acaloiaro/neoq/handler"
|
||||||
"github.com/acaloiaro/neoq/jobs"
|
"github.com/acaloiaro/neoq/jobs"
|
||||||
)
|
)
|
||||||
|
|
@ -17,7 +16,7 @@ func main() {
|
||||||
const queue = "foobar"
|
const queue = "foobar"
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
nq, err := neoq.New(ctx,
|
nq, err := neoq.New(ctx,
|
||||||
config.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"),
|
postgres.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"),
|
||||||
neoq.WithBackend(postgres.Backend),
|
neoq.WithBackend(postgres.Backend),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/acaloiaro/neoq"
|
"github.com/acaloiaro/neoq"
|
||||||
"github.com/acaloiaro/neoq/backends/postgres"
|
"github.com/acaloiaro/neoq/backends/postgres"
|
||||||
"github.com/acaloiaro/neoq/config"
|
|
||||||
"github.com/acaloiaro/neoq/handler"
|
"github.com/acaloiaro/neoq/handler"
|
||||||
"github.com/acaloiaro/neoq/jobs"
|
"github.com/acaloiaro/neoq/jobs"
|
||||||
)
|
)
|
||||||
|
|
@ -16,7 +15,7 @@ func main() {
|
||||||
const queue = "foobar"
|
const queue = "foobar"
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), config.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"))
|
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString("postgres://postgres:postgres@127.0.0.1:5432/neoq"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error initializing postgres backend: %v", err)
|
log.Fatalf("error initializing postgres backend: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
"github.com/acaloiaro/neoq/backends/memory"
|
"github.com/acaloiaro/neoq/backends/memory"
|
||||||
"github.com/acaloiaro/neoq/backends/postgres"
|
"github.com/acaloiaro/neoq/backends/postgres"
|
||||||
"github.com/acaloiaro/neoq/config"
|
|
||||||
"github.com/acaloiaro/neoq/handler"
|
"github.com/acaloiaro/neoq/handler"
|
||||||
"github.com/acaloiaro/neoq/jobs"
|
"github.com/acaloiaro/neoq/jobs"
|
||||||
"github.com/acaloiaro/neoq/testutils"
|
"github.com/acaloiaro/neoq/testutils"
|
||||||
|
|
@ -43,7 +42,7 @@ func ExampleNew_postgres() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nq, err := New(ctx, WithBackend(postgres.Backend), config.WithConnectionString(pgURL))
|
nq, err := New(ctx, WithBackend(postgres.Backend), postgres.WithConnectionString(pgURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("neoq's postgres backend failed to initialize:", err)
|
fmt.Println("neoq's postgres backend failed to initialize:", err)
|
||||||
return
|
return
|
||||||
|
|
@ -76,7 +75,7 @@ func ExampleWithBackend_postgres() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nq, err := New(ctx, WithBackend(postgres.Backend), config.WithConnectionString(pgURL))
|
nq, err := New(ctx, WithBackend(postgres.Backend), postgres.WithConnectionString(pgURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("initializing a new Neoq with no params should not return an error:", err)
|
fmt.Println("initializing a new Neoq with no params should not return an error:", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue