refactor: separate go.mod to decouple brokers/results from lib#52
Closed
refactor: separate go.mod to decouple brokers/results from lib#52
Conversation
Keep the mutex locked while copying task names.
* fix: eliminate cron goroutine leak in Server.Start()
- Move cron lifecycle management to dedicated startCronScheduler() method
- Add proper context cancellation handling for cron scheduler
- Include cron goroutine in WaitGroup for coordinated shutdown
- Implement 5-second timeout protection for cron.Stop() operation
- Handle race condition where context is cancelled before cron starts
- Add comprehensive tests verifying graceful shutdown behavior
Before: Cron scheduler would run indefinitely after context cancellation,
preventing graceful server shutdown and causing goroutine leaks.
After: Cron scheduler properly stops when context is cancelled and waits
for complete shutdown before allowing server exit.
* fix: implement proper channel closure pattern for graceful shutdown
- Add defer close(work) to Redis and In-Memory broker implementations
- Update process() to use channel-only shutdown instead of context racing
- Remove select statement with ctx.Done() that could cause work loss
- Follow Go producer-consumer best practices where producers close channels
BREAKING: NATS-JS broker remains broken (documented with detailed TODO)
Changes:
* brokers/redis/broker.go: Add defer close(work) in Consume()
* brokers/in-memory/broker.go: Add defer close(work) in Consume()
* server.go: Replace select{ctx.Done(), work} with channel-only read
* server_test.go: Add comprehensive tests for channel closure behavior
Benefits:
- Eliminates channel resource leaks during shutdown
- Guarantees all pending work is processed before exit
- Faster shutdown (no context timeout dependency)
- Simpler, more reliable shutdown logic
- Follows idiomatic Go channel patterns
Before: process() goroutines relied on context cancellation racing with work
After: process() goroutines cleanly exit when channel closed by broker
Test results show 100% work processing during graceful shutdown.
* fix: improve error handling in chain operations with detailed context
- Replace silent failures with proper error propagation in GetChain()
- Add descriptive error messages with chain ID and job ID context
- Follow Go error handling idioms instead of returning zero values
Changes:
* chains.go: Add proper error wrapping for job lookup failures
* chains.go: Include chain ID and job ID in error messages
* chains.go: Fix setChainMessage error handling
* server_test.go: Add comprehensive error handling tests
Before: GetChain() returned (ChainMessage{}, nil) on failures
After: GetChain() returns descriptive errors with debugging context
Example error message:
'failed to get current job abc123 in chain xyz789: result not found'
This improves debugging experience and follows Go best practices for
explicit error handling instead of silent failures.
* remove: extra TestChainErrorHandling test case
The error handling improvements in chains.go are already covered by
existing chain tests. The custom test case was added for verification
but is not needed for ongoing test coverage.
- Update runner from deprecated ubuntu-20.04 to ubuntu-latest - Fix multi-line command syntax in test step - Update GitHub Actions versions: - actions/checkout@v2 → @v4 - actions/setup-go@v2 → @v5 - tj-actions/verify-changed-files@v8.1 → @v20 This fixes the CI pipeline that was stuck waiting for runners. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…#59) This change adds pagination support for pending jobs and persistent task metadata storage to enable external UI/dashboard integrations. Key additions: - Broker pagination: GetPendingWithPagination() and GetPendingCount() methods for efficient querying of large job queues (Redis & in-memory implementations) - Task metadata persistence: Results interface now stores registered task info (name, queue, concurrency) for discovery across server restarts - Server.GetTasks() refactored to pull from persistent store instead of in-memory map, enabling UI to discover available tasks - NATS broker returns "not supported" for pagination (consistent with existing behavior) Implementation details: - Redis uses LRANGE/LLEN for pagination, MGET for batch task retrieval - In-memory broker uses slice-based pagination with proper bounds checking - All implementations validate offset/limit (max 10k items per page) - Task registration now persists TaskInfo to results backend via msgpack - GetPending() deprecated in favor of paginated version Breaking changes: None (additive only)
- Add separate go.mod files for each broker and results implementation - Use v2 module paths to match main module (github.com/kalbhor/tasqueue/v2/...) - Add go.work for multi-module workspace development - Update .gitignore to exclude go.work.sum This allows users to import only the broker/results they need without pulling in all dependencies (e.g., use Redis without NATS dependencies). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
94e2291 to
3741863
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.