Releases: pardnchiu/go-queue
Releases · pardnchiu/go-queue
v1.1.3
REFACTOR
- Replace
Queue.closedbool +sync.RWMutexwithatomic.Uint32state - Use CAS in
Start()to ensure transition fromstateCreatedtostateRunningonly - Use CAS loop in
Shutdown()for idempotent closure (allow multiple calls)
UPDATE
- Change
Start()return type toerrorfor state check error reporting - Change
Config.Timeouttype fromint64totime.Duration - Change default
Timeoutfrom30to30 * time.Second
FIX
- Fix
Enqueue()error message formatting, use%wto wrap underlying error - Fix
Shutdown()to callcancel()after completion for context cleanup
REFACTOR
- 將
Queue.closedbool +sync.RWMutex替換為atomic.Uint32state - 在
Start()中使用 CAS 確保只能從stateCreated轉換到stateRunning - 在
Shutdown()中使用 CAS loop 確保冪等性關閉(允許多次調用)
UPDATE
- 修改
Start()返回型別為error,支援狀態檢查錯誤回報 Config.Timeout型別從int64改為time.Duration- 預設
Timeout值從30改為30 * time.Second
FIX
- 修正
Enqueue()錯誤訊息格式化,使用%w包裹底層錯誤 - 修正
Shutdown()在完成後呼叫cancel()清理 context
v1.1.2
REFACTOR
- task.go: Refactored
taskHeapfrom a slice type to a struct, addedtasksandminCapfields to support dynamic minimum capacity. - task.go: Updated
Len,Less,Swap,Push, andPopmethods oftaskHeapto fit the new struct structure. - pending.go: Fixed
newPendinginitialization to calculate dynamic minimum capacity based onworkersandsize(max(16, min(size/8, size/workers))).
PERF
- task.go: Optimized heap shrink logic, changed trigger condition from
capacity > taskHeapMinCap && length < capacity/4tocapacity > minCap*4 && length < capacity/taskHeapMinCapRatio. - task.go: Improved shrink capacity calculation, using
max(capacity/4, minCap)to ensure it does not fall below the minimum capacity. - pending.go: Optimized
promoteLockedaccess efficiency by retrieving thetasksfield first to avoid repeated access.
UPDATE
- new.go: Fixed
newPendingcall, addedworkersparameter.
FIX
- new.go: Added debug log for timeout trigger (
task.timeout_triggered), recording id, preset, and timeout information.
REFACTOR
- task.go: 將
taskHeap從 slice 型別重構為 struct,新增tasks與minCap欄位,支援動態最小容量 - task.go: 調整
taskHeap的Len、Less、Swap、Push、Pop方法,適配新的 struct 結構 - pending.go: 修正
newPending初始化,根據workers與size計算動態最小容量(max(16, min(size/8, size/workers)))
PERF
- task.go: 優化 heap shrink 邏輯,將觸發條件由
capacity > taskHeapMinCap && length < capacity/4改為capacity > minCap*4 && length < capacity/taskHeapMinCapRatio - task.go: 改進縮減容量計算,使用
max(capacity/4, minCap)確保不低於最小容量 - pending.go: 優化
promoteLocked存取效率,先取得tasks欄位避免重複存取
UPDATE
- new.go: 修正
newPending呼叫,新增workers參數
FIX
- new.go: 新增 timeout 觸發時的 debug 日誌(
task.timeout_triggered),記錄 id、preset、timeout 資訊
v1.1.1
REFACTOR
- Changed
PresetConfig.PriorityfromstringtoPrioritytype - Changed
WithRetryparameter from*intto variadic...int, supports invocation without arguments
UPDATE
- Improved
timeoutcalculation logic, now directly usestime.Durationoperations - Updated priority upgrade logic to use new priority constants instead of strings
PERF
- Added
taskHeapcapacity reduction mechanism: when usage drops below 1/4 of capacity, automatically shrinks to half (minimum retained is 16)
REMOVE
- Removed
getPresetPriorityfunction - Set
old[n-1] = nilinPop()to avoid memory leaks
REFACTOR
- 將
PresetConfig.Priority從string改為Priority型別,移除字串解析邏輯 - 將
WithRetry參數從*int改為變長參數...int,支援無參數調用
UPDATE
- 改進
timeout計算邏輯,直接使用time.Duration運算 - 更新優先級升級邏輯,使用新的優先級常數替代字串
PERF
- 新增
taskHeapcap縮減機制,當使用量低於容量1/4時自動縮減至一半(最小保留 16)
REMOVE
- 移除
getPresetPriority函式 - 在
Pop()中設置old[n-1] = nil避免記憶體洩漏
v1.1.0
Features
- Add
Retrypriority level (between High and Normal) - Add error retry mechanism with
WithRetry()option// Enable retry with default max (3 times) q.Enqueue(ctx, "", action, queue.WithRetry(nil)) // Enable retry with custom max maxRetry := 5 q.Enqueue(ctx, "", action, queue.WithRetry(&maxRetry)) // Updated callback (success only) q.Enqueue(ctx, "", action, queue.WithCallback(func(id string) { log.Printf("Task %s completed", id) }))