Skip to content

refactor: separate go.mod to decouple brokers/results from lib#52

Closed
kalbhor wants to merge 5 commits intodevelopfrom
refactor/packages
Closed

refactor: separate go.mod to decouple brokers/results from lib#52
kalbhor wants to merge 5 commits intodevelopfrom
refactor/packages

Conversation

@kalbhor
Copy link
Owner

@kalbhor kalbhor commented Jul 16, 2024

No description provided.

js-ojus and others added 5 commits February 24, 2025 11:01
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>
@kalbhor kalbhor deleted the branch develop January 31, 2026 18:39
@kalbhor kalbhor closed this Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants