[PR #1082] Feature/bus job chain, Allows adding multiple tasks to be executed sequentially. #2017

Open
opened 2026-03-07 22:14:18 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hibiken/asynq/pull/1082
Author: @seth-shi
Created: 10/25/2025
Status: 🔄 Open

Base: masterHead: feature/bus-chain


📝 Commits (5)

  • a11bd17 feat(server): Automatically inject Chain Middleware for ServeMux handlers
  • c94f64d Create chain_test.go
  • 049d166 refactor(tests): Enhance task queue verification and update timeout handling
  • a60b286 test(chain): Add tests for Deadline and ProcessAt options in task chains
  • 39859bd Update chain_test.go

📊 Changes

3 files changed (+1496 additions, -0 deletions)

View changed files

chain.go (+261 -0)
chain_test.go (+1225 -0)
📝 server.go (+10 -0)

📄 Description

Add Chain Task Support

Summary

Add NewChainTask() for sequential task execution. Tasks run in order, chain stops on failure.

Usage

// Create chain
chain := asynq.NewChainTask(
    asynq.NewTask("task1", payload1),
    asynq.NewTask("task2", payload2),
    asynq.NewTask("task3", payload3),
)

// Enqueue like normal task
client.Enqueue(chain)

// Handlers - no special logic needed
mux.HandleFunc("task1", func(ctx context.Context, t *asynq.Task) error {
    // ... process task1
    return nil  // success -> task2 runs
})

Features

  • Tasks execute sequentially
  • Stops on first failure
  • Supports all options (Queue, MaxRetry, Timeout, etc.)
  • Cross-queue support
  • Zero breaking changes
  • 18 tests, 100% pass rate

Files

  • chain.go (256 lines) - Core implementation
  • chain_test.go (1,135 lines) - Test suite
  • server.go - Register middleware

🔄 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/1082 **Author:** [@seth-shi](https://github.com/seth-shi) **Created:** 10/25/2025 **Status:** 🔄 Open **Base:** `master` ← **Head:** `feature/bus-chain` --- ### 📝 Commits (5) - [`a11bd17`](https://github.com/hibiken/asynq/commit/a11bd171af13f69713c277978454836f3483b960) feat(server): Automatically inject Chain Middleware for ServeMux handlers - [`c94f64d`](https://github.com/hibiken/asynq/commit/c94f64dfff59875d77336456152f330bfe37571e) Create chain_test.go - [`049d166`](https://github.com/hibiken/asynq/commit/049d166de500421efe62a863f2949bf6d4c439fb) refactor(tests): Enhance task queue verification and update timeout handling - [`a60b286`](https://github.com/hibiken/asynq/commit/a60b286c32fecb24c8b568f4a32b58c7f45da368) test(chain): Add tests for Deadline and ProcessAt options in task chains - [`39859bd`](https://github.com/hibiken/asynq/commit/39859bd9cb3afc3e0459f76dfbebb99b856415c5) Update chain_test.go ### 📊 Changes **3 files changed** (+1496 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `chain.go` (+261 -0) ➕ `chain_test.go` (+1225 -0) 📝 `server.go` (+10 -0) </details> ### 📄 Description # Add Chain Task Support ## Summary Add `NewChainTask()` for sequential task execution. Tasks run in order, chain stops on failure. ## Usage ```go // Create chain chain := asynq.NewChainTask( asynq.NewTask("task1", payload1), asynq.NewTask("task2", payload2), asynq.NewTask("task3", payload3), ) // Enqueue like normal task client.Enqueue(chain) // Handlers - no special logic needed mux.HandleFunc("task1", func(ctx context.Context, t *asynq.Task) error { // ... process task1 return nil // success -> task2 runs }) ``` ## Features - ✅ Tasks execute sequentially - ✅ Stops on first failure - ✅ Supports all options (Queue, MaxRetry, Timeout, etc.) - ✅ Cross-queue support - ✅ Zero breaking changes - ✅ 18 tests, 100% pass rate ## Files - `chain.go` (256 lines) - Core implementation - `chain_test.go` (1,135 lines) - Test suite - `server.go` - Register middleware --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#2017
No description provided.