[PR #135] [MERGED] Major API Redesign #625

Closed
opened 2026-03-02 05:54:19 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hibiken/asynq/pull/135
Author: @hibiken
Created: 4/12/2020
Status: Merged
Merged: 4/19/2020
Merged by: @hibiken

Base: masterHead: api/server


📝 Commits (10+)

  • 2705b6d Rename Background to Server
  • f131c49 Export Start, Stop and Quiet method on Server type
  • 1036677 Refactor server state
  • 8e47d0b Rename CLI to asynq
  • 68db689 Rename internal ProcessState to ServerState
  • e717149 Update all reference to asynqmon to Asynq CLI
  • 8d87e1d Rename ps command to servers
  • 07e2a54 Update docs with new APIs
  • 15b8360 Update doc comments
  • d96d038 Add test cases for server error

📊 Changes

44 files changed (+1102 additions, -633 deletions)

View changed files

📝 .gitignore (+3 -3)
📝 CHANGELOG.md (+14 -0)
📝 README.md (+14 -12)
background_test.go (+0 -128)
📝 benchmark_test.go (+9 -9)
📝 doc.go (+6 -6)
📝 docs/assets/asynq_history.gif (+0 -0)
📝 docs/assets/asynq_ps.gif (+0 -0)
📝 docs/assets/asynq_stats.gif (+0 -0)
📝 heartbeat.go (+9 -10)
📝 heartbeat_test.go (+39 -14)
📝 internal/asynqtest/asynqtest.go (+3 -3)
📝 internal/base/base.go (+99 -61)
📝 internal/base/base_test.go (+27 -21)
📝 internal/rdb/inspect.go (+13 -13)
📝 internal/rdb/inspect_test.go (+31 -30)
📝 internal/rdb/rdb.go (+20 -20)
📝 internal/rdb/rdb_test.go (+73 -72)
internal/testbroker/testbroker.go (+187 -0)
📝 processor.go (+37 -27)

...and 24 more files

📄 Description

This change introduces a few breaking changes to the package APIs.

  • Renaming Background to Server
  • Exporting Start, Stop and Quiet methods on Server type.
  • Renaming CLI to asynq
  • NewServer constructor takes Config not *Config

After this change, server-side code may look like the following:

func main() {
        r := asynq.RedisClientOpt{Addr: ":6379"}

        srv := asynq.NewServer(r, asynq.Config{
                Concurrency: 20,
                Queues: map[string]int{
                        "critical": 6,
                        "default":  3,
                        "low":      1,
                },
                ErrorHandler:    errHandler,
                ShutdownTimeout: 10 * time.Second,
        })

        mux := asynq.NewServeMux()
        mux.Use(loggingMiddleware)
        mux.HandleFunc(tasks.EmailTask, tasks.HandleEmailTask)

       // Use either Option1 or Option2 below.

        // Option 1 (Let asynq handle system signals)
        if err := srv.Run(mux); err != nil {
                log.Fatalf("could not run server: %v", err)
        }

        // Option 2 (Handle system signals yourself!)
        if err := srv.Start(mux); err != nil {
                log.Fatalf("could not start server: %v", err)
        }
        sigs := make(chan os.Signal, 1)
        signal.Notify(sigs, unix.SIGTERM, unix.SIGINT, unix.SIGTSTP)
        for {
                s := <-sigs
                if s == unix.SIGTSTP {
                        srv.Quiet() // Stop processing new tasks
                        continue
                }
                break
        }
        srv.Stop()
}
  • Update doc comment in server.go
  • Add ShutdownTimeout to Config
  • Handle error when server cannot connect to Redis (don't panic)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hibiken/asynq/pull/135 **Author:** [@hibiken](https://github.com/hibiken) **Created:** 4/12/2020 **Status:** ✅ Merged **Merged:** 4/19/2020 **Merged by:** [@hibiken](https://github.com/hibiken) **Base:** `master` ← **Head:** `api/server` --- ### 📝 Commits (10+) - [`2705b6d`](https://github.com/hibiken/asynq/commit/2705b6d4527d9740f28d272e4e0efe2d0384696b) Rename Background to Server - [`f131c49`](https://github.com/hibiken/asynq/commit/f131c495b64e21f5b8d926e0df0e174a45028a93) Export Start, Stop and Quiet method on Server type - [`1036677`](https://github.com/hibiken/asynq/commit/10366771093615b0f6ab7cd302e7190dc77a3267) Refactor server state - [`8e47d0b`](https://github.com/hibiken/asynq/commit/8e47d0b751a842481df249840adbea7a6808aa71) Rename CLI to asynq - [`68db689`](https://github.com/hibiken/asynq/commit/68db689cdca582cdd0ef253c1a36bc2d4524e1f6) Rename internal ProcessState to ServerState - [`e717149`](https://github.com/hibiken/asynq/commit/e717149833da38b830a52871112f7d3b9fcf616e) Update all reference to asynqmon to Asynq CLI - [`8d87e1d`](https://github.com/hibiken/asynq/commit/8d87e1d19d99f7078684f699aa770478e6f06363) Rename ps command to servers - [`07e2a54`](https://github.com/hibiken/asynq/commit/07e2a54285b6f49221d83fa17d1b465aa7edf710) Update docs with new APIs - [`15b8360`](https://github.com/hibiken/asynq/commit/15b836049d9ceb5a3916b2289b12acfb6e01f40e) Update doc comments - [`d96d038`](https://github.com/hibiken/asynq/commit/d96d038b5470a444311591fa1a9acaef2e10f37d) Add test cases for server error ### 📊 Changes **44 files changed** (+1102 additions, -633 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+3 -3) 📝 `CHANGELOG.md` (+14 -0) 📝 `README.md` (+14 -12) ➖ `background_test.go` (+0 -128) 📝 `benchmark_test.go` (+9 -9) 📝 `doc.go` (+6 -6) 📝 `docs/assets/asynq_history.gif` (+0 -0) 📝 `docs/assets/asynq_ps.gif` (+0 -0) 📝 `docs/assets/asynq_stats.gif` (+0 -0) 📝 `heartbeat.go` (+9 -10) 📝 `heartbeat_test.go` (+39 -14) 📝 `internal/asynqtest/asynqtest.go` (+3 -3) 📝 `internal/base/base.go` (+99 -61) 📝 `internal/base/base_test.go` (+27 -21) 📝 `internal/rdb/inspect.go` (+13 -13) 📝 `internal/rdb/inspect_test.go` (+31 -30) 📝 `internal/rdb/rdb.go` (+20 -20) 📝 `internal/rdb/rdb_test.go` (+73 -72) ➕ `internal/testbroker/testbroker.go` (+187 -0) 📝 `processor.go` (+37 -27) _...and 24 more files_ </details> ### 📄 Description This change introduces a few breaking changes to the package APIs. - Renaming `Background` to `Server` - Exporting `Start`, `Stop` and `Quiet` methods on `Server` type. - Renaming CLI to `asynq` - `NewServer` constructor takes `Config` not `*Config` After this change, server-side code may look like the following: ```go func main() { r := asynq.RedisClientOpt{Addr: ":6379"} srv := asynq.NewServer(r, asynq.Config{ Concurrency: 20, Queues: map[string]int{ "critical": 6, "default": 3, "low": 1, }, ErrorHandler: errHandler, ShutdownTimeout: 10 * time.Second, }) mux := asynq.NewServeMux() mux.Use(loggingMiddleware) mux.HandleFunc(tasks.EmailTask, tasks.HandleEmailTask) // Use either Option1 or Option2 below. // Option 1 (Let asynq handle system signals) if err := srv.Run(mux); err != nil { log.Fatalf("could not run server: %v", err) } // Option 2 (Handle system signals yourself!) if err := srv.Start(mux); err != nil { log.Fatalf("could not start server: %v", err) } sigs := make(chan os.Signal, 1) signal.Notify(sigs, unix.SIGTERM, unix.SIGINT, unix.SIGTSTP) for { s := <-sigs if s == unix.SIGTSTP { srv.Quiet() // Stop processing new tasks continue } break } srv.Stop() } ``` - [x] Update doc comment in server.go - [x] Add ShutdownTimeout to Config - [x] Handle error when server cannot connect to Redis (don't panic) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 05:54:19 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#625
No description provided.