-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This goal of this change is to simplify the API. Handlers and queues have a 1:1 mapping, so functions that receive both a `queue` and a `handler` take two parameters when they could take only one.
- Loading branch information
Showing
17 changed files
with
112 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ Queue Handlers are simple Go functions that accept a `Context` parameter. | |
```go | ||
ctx := context.Background() | ||
nq, _ := neoq.New(ctx, neoq.WithBackend(memory.Backend)) | ||
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) { | ||
nq.Start(ctx, handler.New("greetings", func(ctx context.Context) (err error) { | ||
j, _ := jobs.FromContext(ctx) | ||
log.Println("got job id:", j.ID, "messsage:", j.Payload["message"]) | ||
return | ||
|
@@ -57,22 +57,22 @@ nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) { | |
|
||
Enqueuing adds jobs to the specified queue to be processed asynchronously. | ||
|
||
**Example**: Add a "Hello World" job to the `hello_world` queue using the default in-memory backend. | ||
**Example**: Add a "Hello World" job to the `greetings` queue using the default in-memory backend. | ||
|
||
```go | ||
ctx := context.Background() | ||
nq, _ := neoq.New(ctx, neoq.WithBackend(memory.Backend)) | ||
nq.Enqueue(ctx, &jobs.Job{ | ||
Queue: "hello_world", | ||
Payload: map[string]interface{}{ | ||
Queue: "greetings", | ||
Payload: map[string]any{ | ||
"message": "hello world", | ||
}, | ||
}) | ||
``` | ||
|
||
## Redis | ||
|
||
**Example**: Process jobs on the "hello_world" queue and add a job to it using the redis backend | ||
**Example**: Process jobs on the "greetings" queue and add a job to it using the redis backend | ||
|
||
```go | ||
ctx := context.Background() | ||
|
@@ -81,14 +81,14 @@ nq, _ := neoq.New(ctx, | |
redis.WithAddr("localhost:6379"), | ||
redis.WithPassword("")) | ||
|
||
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) { | ||
nq.Start(ctx, handler.New("greetings", func(ctx context.Context) (err error) { | ||
j, _ := jobs.FromContext(ctx) | ||
log.Println("got job id:", j.ID, "messsage:", j.Payload["message"]) | ||
return | ||
})) | ||
|
||
nq.Enqueue(ctx, &jobs.Job{ | ||
Queue: "hello_world", | ||
Queue: "greetings", | ||
Payload: map[string]interface{}{ | ||
"message": "hello world", | ||
}, | ||
|
@@ -97,7 +97,7 @@ nq.Enqueue(ctx, &jobs.Job{ | |
|
||
## Postgres | ||
|
||
**Example**: Process jobs on the "hello_world" queue and add a job to it using the postgres backend | ||
**Example**: Process jobs on the "greetings" queue and add a job to it using the postgres backend | ||
|
||
```go | ||
ctx := context.Background() | ||
|
@@ -106,14 +106,14 @@ nq, _ := neoq.New(ctx, | |
postgres.WithConnectionString("postgres://postgres:[email protected]:5432/neoq"), | ||
) | ||
|
||
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) { | ||
nq.Start(ctx, handler.New("greetings", func(ctx context.Context) (err error) { | ||
j, _ := jobs.FromContext(ctx) | ||
log.Println("got job id:", j.ID, "messsage:", j.Payload["message"]) | ||
return | ||
})) | ||
|
||
nq.Enqueue(ctx, &jobs.Job{ | ||
Queue: "hello_world", | ||
Queue: "greetings", | ||
Payload: map[string]interface{}{ | ||
"message": "hello world", | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.