2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 11:05:58 +08:00

Update docs with new APIs

This commit is contained in:
Ken Hibino 2020-04-12 17:16:44 -07:00
parent b086e88a47
commit 24da281aa7
3 changed files with 16 additions and 7 deletions

View File

@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- `Background` type is renamed to `Server`.
- To upgrade from the previous version, Update `NewBackground` to `NewServer` and pass `Config` by value.
- New `Server` type exposes `Start`, `Stop`, and `Quiet` as well as `Run`.
- CLI is renamed to `asynq`.
- To upgrade to the latest version run `go get -u github.com/hibiken/tools/asynq`
- The `ps` command in CLI is renamed to `servers`
## [0.7.1] - 2020-04-05 ## [0.7.1] - 2020-04-05
### Fixed ### Fixed

View File

@ -161,8 +161,8 @@ func main() {
} }
``` ```
Next, create a binary to process these tasks in the background. Next, create a work server binary to process these tasks in the background.
To start the background workers, use [`Background`](https://pkg.go.dev/github.com/hibiken/asynq?tab=doc#Background) and provide your [`Handler`](https://pkg.go.dev/github.com/hibiken/asynq?tab=doc#Handler) to process the tasks. To start the background workers, use [`Server`](https://pkg.go.dev/github.com/hibiken/asynq?tab=doc#Server) and provide your [`Handler`](https://pkg.go.dev/github.com/hibiken/asynq?tab=doc#Handler) to process the tasks.
You can optionally use [`ServeMux`](https://pkg.go.dev/github.com/hibiken/asynq?tab=doc#ServeMux) to create a handler, just as you would with [`"net/http"`](https://golang.org/pkg/net/http/) Handler. You can optionally use [`ServeMux`](https://pkg.go.dev/github.com/hibiken/asynq?tab=doc#ServeMux) to create a handler, just as you would with [`"net/http"`](https://golang.org/pkg/net/http/) Handler.
@ -179,7 +179,7 @@ const redisAddr = "127.0.0.1:6379"
func main() { func main() {
r := &asynq.RedisClientOpt{Addr: redisAddr} r := &asynq.RedisClientOpt{Addr: redisAddr}
bg := asynq.NewBackground(r, &asynq.Config{ srv := asynq.NewServer(r, asynq.Config{
// Specify how many concurrent workers to use // Specify how many concurrent workers to use
Concurrency: 10, Concurrency: 10,
// Optionally specify multiple queues with different priority. // Optionally specify multiple queues with different priority.
@ -197,7 +197,7 @@ func main() {
mux.HandleFunc(tasks.ImageProcessing, tasks.HandleImageProcessingTask) mux.HandleFunc(tasks.ImageProcessing, tasks.HandleImageProcessingTask)
// ...register other handlers... // ...register other handlers...
bg.Run(mux) srv.Run(mux)
} }
``` ```

6
doc.go
View File

@ -30,13 +30,13 @@ Task is created with two parameters: its type and payload.
// Schedule the task to be processed in one minute. // Schedule the task to be processed in one minute.
err = client.EnqueueIn(time.Minute, t) err = client.EnqueueIn(time.Minute, t)
The Background is used to run the background task processing with a given The Server is used to run the background task processing with a given
handler. handler.
bg := asynq.NewBackground(redis, &asynq.Config{ srv := asynq.NewServer(redis, asynq.Config{
Concurrency: 10, Concurrency: 10,
}) })
bg.Run(handler) srv.Run(handler)
Handler is an interface with one method ProcessTask which Handler is an interface with one method ProcessTask which
takes a task and returns an error. Handler should return nil if takes a task and returns an error. Handler should return nil if