[messages] fix queue stuck on scheduled messages#362
Conversation
🤖 Pull request artifacts
|
WalkthroughDAO SQL for computing the next scheduled send was changed to coalesce NULL Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant MessagesService
participant MessagesDao
participant SendMessagesWorker
Client->>MessagesService: enqueueMessage(message, scheduleAt?, priority)
MessagesService->>MessagesDao: nextScheduledTime()
MessagesDao-->>MessagesService: nextScheduled (ms or null/0)
alt scheduleAt in future AND (nextScheduled == null OR scheduleAt < nextScheduled)
MessagesService->>SendMessagesWorker: start(expedited=true, scheduleAt)
else
alt nextScheduled == null OR priority >= PRIORITY_EXPEDITED
MessagesService->>SendMessagesWorker: start(expedited=true)
else
MessagesService-->>Client: enqueue without expedited start
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (1)
99-102: Remove dead code.This commented-out block appears to be remnants of the old implementation and should be removed to keep the codebase clean.
🧹 Suggested cleanup
val nextScheduled = dao.nextScheduledTime()?.takeIf { it > 0 } -// val earliest = request.params.scheduleAt?.let { -// val nextScheduled = dao.nextScheduledTime() ?: 0 -// nextScheduled != 0L && it.time < nextScheduled -// } ?: true - val message = try {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt` around lines 99 - 102, Remove the dead commented-out block that defines the local variable "earliest" in MessagesService (the lines referencing request.params.scheduleAt, dao.nextScheduledTime(), and nextScheduled); delete the entire commented section so the file no longer contains this stale implementation and commit the cleanup to keep MessagesService.kt tidy.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt`:
- Around line 99-102: Remove the dead commented-out block that defines the local
variable "earliest" in MessagesService (the lines referencing
request.params.scheduleAt, dao.nextScheduledTime(), and nextScheduled); delete
the entire commented section so the file no longer contains this stale
implementation and commit the cleanup to keep MessagesService.kt tidy.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e901868c-54e0-437c-8082-d212c3698b6e
📒 Files selected for processing (2)
app/src/main/java/me/capcom/smsgateway/data/dao/MessagesDao.ktapp/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt`:
- Around line 97-113: The code collapses the distinct dao.nextScheduledTime()
states by using .takeIf { it > 0 }; revert to val nextScheduled =
dao.nextScheduledTime() (so 0 stays distinct from null) and change the
future-scheduling comparison to use scheduleAt < (nextScheduled ?:
Long.MAX_VALUE) in the block that calls SendMessagesWorker.start, keeping the
existing else-branch logic that checks nextScheduled == null || priority >=
Message.PRIORITY_EXPEDITED; this preserves the three-state semantics (null, 0,
>0) and avoids cancelling an in-flight worker.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1761504d-bf6d-4d03-b5a0-c6bc5f9ffb82
📒 Files selected for processing (1)
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
88c5ae7 to
c3dbc59
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt (1)
97-113:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPreserve
nextScheduledthree-state semantics (null,0,>0).Line 97 collapses
0tonull, which breaks the distinction introduced byMessagesDao.nextScheduledTime()and can cause incorrect force/replace behavior at Line 113.Suggested fix
- val nextScheduled = dao.nextScheduledTime()?.takeIf { it > 0 } + val nextScheduled = dao.nextScheduledTime() @@ if (scheduleAt != null && scheduleAt > System.currentTimeMillis() - && scheduleAt < (nextScheduled ?: 0) + && scheduleAt < (nextScheduled ?: Long.MAX_VALUE) ) { SendMessagesWorker.start(context, true, scheduleAt) } else { SendMessagesWorker.start( context, - nextScheduled == null || priority >= Message.PRIORITY_EXPEDITED, + priority >= Message.PRIORITY_EXPEDITED, SendMessagesWorker.IMMEDIATE ) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt` around lines 97 - 113, The code collapses a zero nextScheduled to null by using takeIf { it > 0 }, losing the three-state semantics (null, 0, >0); replace val nextScheduled = dao.nextScheduledTime()?.takeIf { it > 0 } with the raw value from MessagesDao (e.g., val nextScheduled = dao.nextScheduledTime()) and update the comparison in the scheduling branch to treat a null as "no scheduled time" by using a safe fallback (for example compare scheduleAt < (nextScheduled ?: Long.MAX_VALUE)); keep the later check that uses nextScheduled == null || priority >= Message.PRIORITY_EXPEDITED unchanged so the original null/0/>0 semantics are preserved for SendMessagesWorker.start.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@app/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt`:
- Around line 97-113: The code collapses a zero nextScheduled to null by using
takeIf { it > 0 }, losing the three-state semantics (null, 0, >0); replace val
nextScheduled = dao.nextScheduledTime()?.takeIf { it > 0 } with the raw value
from MessagesDao (e.g., val nextScheduled = dao.nextScheduledTime()) and update
the comparison in the scheduling branch to treat a null as "no scheduled time"
by using a safe fallback (for example compare scheduleAt < (nextScheduled ?:
Long.MAX_VALUE)); keep the later check that uses nextScheduled == null ||
priority >= Message.PRIORITY_EXPEDITED unchanged so the original null/0/>0
semantics are preserved for SendMessagesWorker.start.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7dd5b5bc-57d0-46d2-a10b-ef91ac345dcf
📒 Files selected for processing (2)
app/src/main/java/me/capcom/smsgateway/data/dao/MessagesDao.ktapp/src/main/java/me/capcom/smsgateway/modules/messages/MessagesService.kt
Summary by CodeRabbit