Simple, reliable, and efficient distributed task queue in Go
asynq puts tasks in Redis and runs them in a worker process, with delay and retry.
Add the module. Redis has to be running first.
go get github.com/hibiken/asynqEnqueue a task whose type name matches the handler you register.
client := asynq.NewClient(asynq.RedisClientOpt{Addr: "localhost:6379"})
client.Enqueue(asynq.NewTask("email:send", []byte(`{"to":"[email protected]"}`)))It does not ship Redis. If the task type does not match a handler, the task fails.
Simple, reliable, and efficient distributed task queue in Go
Asynq is a Go library for queueing tasks and processing them asynchronously with workers. It's backed by Redis and is designed to be scalable yet easy to get started.
Highlevel overview of how Asynq works:
Task queues are used as a mechanism to distribute work across multiple machines. A system can consist of multiple worker servers and brokers, giving way to high availability and horizontal scaling.
Example use case
Status: The library relatively stable and is currently undergoing moderate development with less frequent breaking API changes.
☝️ Important Note: Current major version is zero (
v0.x.x) to accommodate rapid development and fast iteration while getting early feedback from users (feedback on APIs are appreciated!). The public API could change without a major version update beforev1.0.0release.
Some of the lua scripts in this library may not be compatible with Redis Cluster.
If you are using this package in production, please consider sponsoring the project to show your support!
Make sure you have Go installed (download). The last two Go versions are supported (See https://go.dev/dl).
Initialize your project by creating a folder and then running go mod init github.com/your/repo (learn more) inside the folder. Then install Asynq library with the go get command:
go get -u github.com/hibiken/asynqMake sure you're running a Redis server locally or from a Docker container. Version 4.0 or higher is required.
Next, write a package that encapsulates task creation and task handling.
…In your application code, import the above package and use Client to put tasks on queues.
…Next, start a worker server to process these tasks in the background. To start the background workers, use Server and provide your Handler to process the tasks.
You can optionally use ServeMux to create a handler, just as you would with net/http Handler.
…For a more detailed walk-through of the library, see our Getting Started guide.
To learn more about asynq features and APIs, see the package godoc.
Asynqmon is a web based tool for monitoring and administrating Asynq queues and tasks.
Here's a few screenshots of the Web UI:
Queues view
Tasks view
Metrics view
Settings and adaptive dark mode
For details on how to use the tool, refer to the tool's README.
Asynq ships with a command line tool to inspect the state of queues and tasks.
To install the CLI tool, run the following command:
go install github.com/hibiken/asynq/tools/asynq@latestHere's an example of running the asynq dash command:
For details on how to use the tool, refer to the tool's README.
We are open to, and grateful for, any contributions (GitHub issues/PRs, feedback on Gitter channel, etc) made by the community.
Please see the Contribution Guide before contributing.
Copyright (c) 2019-present Ken Hibino and Contributors. Asynq is free and open-source software licensed under the MIT License. Official logo was created by Vic Shóstak and distributed under Creative Commons license (CC0 1.0 Universal).
[BUG] GetQueueInfo doesn't return expected errors
[BUG] EnqueueContext loses underlying Redis errors returned by Lua scripts
Inspector.GetQueueInfo is O(#groups) and blocks Redis for seconds when a queue has many aggregation groups
[FEATURE REQUEST] Support headers in Task metadata (e.g., OpenTelemetry context propagation)
[FEATURE REQUEST] Set TTL on scheduler_history key
[FEATURE REQUEST] Need second level cron spec support
Clarify which Lua scripts are incompatible with Redis Cluster
[BUG] asynq stats: redis eval error: attempt to perform arithmetic on local 'bytes' (a boolean value)
[BUG] ResultWriter.Write creates an orphan task hash when the task no longer exists
Unique(TTL < 1s) silently creates permanent lock due to int(ttl.Seconds()) truncation to 0