mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-17 20:30:06 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
84b0c76c8b | ||
![]() |
60b887b8e3 | ||
![]() |
7864bea55c | ||
![]() |
47220554ca |
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.7.1] - 2020-04-05
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed signal handling for windows.
|
||||
|
||||
## [0.7.0] - 2020-03-22
|
||||
|
||||
### Changed
|
||||
|
25
README.md
25
README.md
@@ -10,10 +10,23 @@
|
||||
Asynq is a simple Go library for queueing tasks and processing them in the background with workers.
|
||||
It is backed by Redis and it is designed to have a low barrier to entry. It should be integrated in your web stack easily.
|
||||
|
||||
**Important Note**: Current major version is zero (v0.x.x) to accomodate rapid development and fast iteration while getting early feedback from users. The public API could change without a major version update before v1.0.0 release.
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- Guaranteed at least one execution of a task
|
||||
- Scheduling of tasks
|
||||
- Durability since tasks are written to Redis
|
||||
- Retries of failed tasks
|
||||
- Concurrency management via configuration
|
||||
- Weighted priority queues
|
||||
- Strict priority queues
|
||||
- Low latency to add a task since writes are fast in Redis
|
||||
- De-duplication of tasks using unique option
|
||||
- Allow timeout and deadline per task
|
||||
- Flexible handler interface with support for middlewares
|
||||
- CLI to inspect and remote-control queues and tasks
|
||||
|
||||
## Quickstart
|
||||
|
||||
First, make sure you are running a Redis server locally.
|
||||
@@ -22,7 +35,7 @@ First, make sure you are running a Redis server locally.
|
||||
$ redis-server
|
||||
```
|
||||
|
||||
Next, write a package that encapslates task creation and task handling.
|
||||
Next, write a package that encapsulates task creation and task handling.
|
||||
|
||||
```go
|
||||
package tasks
|
||||
@@ -207,6 +220,12 @@ go get -u github.com/hibiken/asynq/tools/asynqmon
|
||||
| [Redis](https://redis.io/) | v2.8+ |
|
||||
| [Go](https://golang.org/) | v1.13+ |
|
||||
|
||||
## Stability and Compatibility
|
||||
|
||||
**Important Note**: Current major version is zero (v0.x.x) to accomodate rapid development and fast iteration while getting early feedback from users. The public API could change without a major version update before v1.0.0 release.
|
||||
|
||||
The library is getting close to a stable release, and we are trying to minimize breaking API changes. However, we cannot make any guarantees at this time.
|
||||
|
||||
## Contributing
|
||||
|
||||
We are open to, and grateful for, any contributions (Github issues/pull-requests, feedback on Gitter channel, etc) made by the community.
|
||||
|
@@ -10,9 +10,7 @@ import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/hibiken/asynq/internal/base"
|
||||
@@ -252,18 +250,7 @@ func (bg *Background) Run(handler Handler) {
|
||||
bg.logger.Info("Send signal TSTP to stop processing new tasks")
|
||||
bg.logger.Info("Send signal TERM or INT to terminate the process")
|
||||
|
||||
// Wait for a signal to terminate.
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGTSTP)
|
||||
for {
|
||||
sig := <-sigs
|
||||
if sig == syscall.SIGTSTP {
|
||||
bg.processor.stop()
|
||||
bg.ps.SetStatus(base.StatusStopped)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
bg.waitForSignals()
|
||||
fmt.Println()
|
||||
bg.logger.Info("Starting graceful shutdown")
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
||||
github.com/rs/xid v1.2.1
|
||||
github.com/spf13/cast v1.3.1
|
||||
go.uber.org/goleak v0.10.0
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e // indirect
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
|
||||
gopkg.in/yaml.v2 v2.2.7 // indirect
|
||||
)
|
||||
|
30
signals_unix.go
Normal file
30
signals_unix.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// +build linux bsd darwin
|
||||
|
||||
package asynq
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/hibiken/asynq/internal/base"
|
||||
)
|
||||
|
||||
// waitForSignals waits for signals and handles them.
|
||||
// It handles SIGTERM, SIGINT, and SIGTSTP.
|
||||
// SIGTERM and SIGINT will signal the process to exit.
|
||||
// SIGTSTP will signal the process to stop processing new tasks.
|
||||
func (bg *Background) waitForSignals() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, unix.SIGTERM, unix.SIGINT, unix.SIGTSTP)
|
||||
for {
|
||||
sig := <-sigs
|
||||
if sig == unix.SIGTSTP {
|
||||
bg.processor.stop()
|
||||
bg.ps.SetStatus(base.StatusStopped)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
21
signals_windows.go
Normal file
21
signals_windows.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// +build windows
|
||||
|
||||
package asynq
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// waitForSignals waits for signals and handles them.
|
||||
// It handles SIGTERM and SIGINT.
|
||||
// SIGTERM and SIGINT will signal the process to exit.
|
||||
//
|
||||
// Note: Currently SIGTSTP is not supported for windows build.
|
||||
func (bg *Background) waitForSignals() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, windows.SIGTERM, windows.SIGINT)
|
||||
<-sigs
|
||||
}
|
Reference in New Issue
Block a user