-
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.
- Loading branch information
Showing
27 changed files
with
1,321 additions
and
1,119 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,33 +41,59 @@ Queue handlers listen for Jobs on queues. Jobs may consist of any payload that i | |
|
||
Queue Handlers are simple Go functions that accept a `Context` parameter. | ||
|
||
**Example**: Add a listener on the `hello_world` queue | ||
**Example**: Add a listener on the `hello_world` queue using the default in-memory backend | ||
|
||
```go | ||
ctx := context.Background() | ||
nq, _ := neoq.New(ctx) | ||
nq.Listen(ctx, "hello_world", neoq.NewHandler(func(ctx context.Context) (err error) { | ||
j, err := neoq.JobFromContext(ctx) | ||
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) { | ||
j, _ := handler.JobFromContext(ctx) | ||
log.Println("got job id:", j.ID, "messsage:", j.Payload["message"]) | ||
return | ||
})) | ||
``` | ||
|
||
## Enqueue jobs | ||
|
||
**Example**: Add a "Hello World" job to the `hello_world` queue | ||
Enqueuing jobs 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. | ||
|
||
```go | ||
ctx := context.Background() | ||
nq, _ := neoq.New(ctx) | ||
jid, _ := nq.Enqueue(ctx, neoq.Job{ | ||
jid, _ := nq.Enqueue(ctx, &jobs.Job{ | ||
Queue: "hello_world", | ||
Payload: map[string]interface{}{ | ||
"message": "hello world", | ||
}, | ||
}) | ||
``` | ||
|
||
## Postgres | ||
|
||
**Example**: Process jobs on the "hello_world" queue and add a job to it using the postgres backend | ||
|
||
```go | ||
ctx := context.Background() | ||
nq, _ := neoq.New(ctx, | ||
neoq.WithBackend(postgres.Backend), | ||
config.WithConnectionString("postgres://postgres:[email protected]:5432/neoq"), | ||
) | ||
|
||
nq.Start(ctx, "hello_world", handler.New(func(ctx context.Context) (err error) { | ||
j, _ := handler.JobFromContext(ctx) | ||
log.Println("got job id:", j.ID, "messsage:", j.Payload["message"]) | ||
return | ||
})) | ||
|
||
nq.Enqueue(ctx, &jobs.Job{ | ||
Queue: "hello_world", | ||
Payload: map[string]interface{}{ | ||
"message": "hello world", | ||
}, | ||
}) | ||
``` | ||
# Example Code | ||
|
||
Additional example integration code can be found at https://github.com/acaloiaro/neoq/tree/main/examples | ||
|
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Package backends provides concrete implementations of [pkg/github.com/acaloiaro/neoq/types.Backend] | ||
// | ||
// These backends provide the bulk of Neoq's functionality. | ||
package backends |
Oops, something went wrong.