Repository navigation
fix: duplicate background tasks - #491
Merged
Merged
Conversation
Closed
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.
This pull request introduces several improvements and fixes across the codebase, focusing on database reliability, concurrency, error handling, and code modernization. The most significant changes include making thread closure and message number allocation atomic and robust, improving error logging, updating user fetching methods for consistency, and adding comprehensive tests for database operations.
Database reliability and concurrency improvements:
close_threadto be idempotent, returning a boolean to indicate if the thread was actually closed, and ensuring concurrent close attempts do not overwrite each other's metadata. The SQL update now only affects open threads (status = 1). [1] [2]allocate_next_message_numberto use a single atomic SQL statement withRETURNING, ensuring unique message numbers even under heavy concurrency, and added a test to verify uniqueness. [1] [2]Error handling and logging:
update_thread_status_db) with explicit error logging usingeprintln!in multiple commands, improving observability of failures. [1] [2] [3] [4] [5] [6] [7]User fetching modernization:
ctx.http.get_userto use the more idiomaticUserId::to_user(&ctx)method, ensuring consistency and leveraging the latest library patterns. [1] [2] [3] [4] [5]Testing and code quality:
update_thread_status_dbmodule, improving code safety and reliability.Other codebase improvements:
LazyLock, ensuring one timer per reminder ID and improving reminder scheduling. [1] [2] [3]FlagGuard) for managing atomic flags in the ready handler, ensuring proper cleanup even if tasks panic.These changes collectively improve the robustness, maintainability, and observability of the application.