Skip to content

Commit

Permalink
Move backends to separate packages
Browse files Browse the repository at this point in the history
  • Loading branch information
acaloiaro committed Mar 1, 2023
1 parent 1911da5 commit 5b66209
Show file tree
Hide file tree
Showing 27 changed files with 1,321 additions and 1,119 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/todo_to_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
description: "By default, the commit entered above is compared to the one directly before it; to go back further, enter an earlier SHA here"
required: false
push:
branches:
- main

jobs:
build:
runs-on: "ubuntu-latest"
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ run:
issues-exit-code: 1
tests: true
# list of build tags, all linters use it. Default is empty list.
#build-tags:
build-tags: testing

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
Expand Down Expand Up @@ -133,7 +133,7 @@ linters:
- goconst
- gocritic
- gocyclo
- godox
# - godox
- goerr113
- gofmt
- goheader
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test: install-gotestsum
-count=5 \
-race \
-cover \
-tags testing \
-coverprofile=tmp/coverage/coverage.out \
./...

Expand Down
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions backends/doc.go
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
Loading

0 comments on commit 5b66209

Please sign in to comment.