Repository navigation
feat(dispatch): 沒搶到的司機也要知道——補送 ride.taken 與取消時的 ride.cancelled(T2/T3) - #59
Merged
Merged
Conversation
一輪派單會同時推給半徑內每一位待命司機,只有一位搶得到。先前沒搶到的人手機上 留著一張全螢幕接單卡,而後端沒有任何方式通知他們:ride.accepted 只送給接到的那位, 逾時取消也只通知乘客。他得自己按下去、拿到「手慢了,這單已被其他司機接走」才會消失。 根因是 dispatchRound 的 offered 只是遞迴中的記憶體 map,接單/取消流程拿不到。 改法:Redis 加 ride:<id>:offered 集合(比照既有的 rejected),pushOffer 時記錄; 接單時對「除了接單者以外」的人送 ride.taken、取消(逾時或乘客/客服)時送 ride.cancelled, 送完即清集合。 ride.taken 是新事件型別——不能用 ride.cancelled 代替:訂單並沒有取消,只是不是他的了。 測試:新增 2 案(真 PostGIS+Redis):接單只送沒搶到的那位且集合清空、逾時取消也會送。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
thothawei
added a commit
that referenced
this pull request
Jul 29, 2026
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.
問題
一輪派單會同時推給半徑內每一位待命司機(
dispatchRound迴圈pushOffer),只有一位搶得到。沒搶到的人手機上留著一張全螢幕接單卡,而後端沒有任何方式通知他們:ride.accepted只送給接到的那位;giveUpIfUnaccepted)只通知乘客;status=Assigned),同樣沒人通知那些司機。結果:他得自己按下去、拿到「手慢了,這單已被其他司機接走」才會消失——期間那張卡蓋著整個畫面,新派單來了也只是再疊一張。每一趟車都會發生在所有沒搶到的司機身上。
根因
dispatchRound的offered只是遞迴中的記憶體 map,接單/取消流程根本拿不到那份名單。改法
ride:<id>:offered集合(比照既有的ride:<id>:rejected,同樣 30 分鐘 TTL),pushOffer時 SADD。記錄失敗只記 log——漏記一位的後果是他的卡片留著(=修正前的行為),不該擋住派單。ride.taken(新事件型別)。ride.cancelled(App 端既有處理已能收掉卡片)。ClearOffered,重派時不會誤發給舊名單。為什麼要新型別:不能用
ride.cancelled代替ride.taken——訂單並沒有取消,只是不是他的了;送 cancelled 會讓 App 端把它當成「這單沒了」處理(現在剛好一樣是清卡片,但語義錯了,日後要顯示原因就會出錯)。驗收
go build ./.../go vet/gofmt乾淨。TestAcceptRide_通知沒搶到的司機:ride.taken只送給沒搶到那位(接到的那位不該收到)、且 offered 集合用後清空;TestGiveUp逾時取消_通知收過offer的司機:逾時取消時他也收得到ride.cancelled。notifyOfferedDrivers後第一案 FAIL。App 端對應:fleet-app 的 PR(收到
ride.taken就把接單卡收掉,且不報錯——他什麼都沒做)。🤖 Generated with Claude Code