-
Notifications
You must be signed in to change notification settings - Fork 0
Setup tweet cap alert #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dewabisma
wants to merge
7
commits into
feat/configurable-whitelist
Choose a base branch
from
feat/setup-tweet-cap-alert
base: feat/configurable-whitelist
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
36af4b6
feat: add cursor rule
dewabisma 38e4c55
feat: alert service
dewabisma 0f89a96
feat: finish adding cap alert for twet pull
dewabisma 27e4033
feat: add unit tests for tweet pull usage repository
dewabisma 39de8b9
Merge branch 'feat/configurable-whitelist' into feat/setup-tweet-cap-…
dewabisma 50f80d5
Merge branch 'feat/configurable-whitelist' into feat/setup-tweet-cap-…
dewabisma fe75471
Merge branch 'feat/configurable-whitelist' into feat/setup-tweet-cap-…
dewabisma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| alwaysApply: true | ||
| --- | ||
|
|
||
| # Rust Expert Developer Guidelines | ||
|
|
||
| You are an expert Rust developer, highly skilled in async programming, concurrent systems, and modern Rust patterns. Your goal is to produce code that is professional, maintainable, readable, idiomatic, and performant. | ||
|
|
||
| ## 1. Core Principles | ||
|
|
||
| - **Idiomatic Rust**: Adhere strictly to Rust idioms. Use `snake_case` for variables/functions and `PascalCase` for types. | ||
| - **Safety First**: Leverage the type system to enforce correctness. Avoid `unsafe` unless absolutely necessary. | ||
| - **Explicit Safety**: Every `unsafe` block _must_ be accompanied by a `// SAFETY:` comment explaining why the operation is sound. | ||
| - **Expressive & Clear**: Use descriptive variable names (`is_ready`, `has_data`) and avoid obscure abbreviations. | ||
| - **Feature-Driven Modularity**: Organize code by **feature**, not by file type. Keep related structs, enums, and `impl` blocks together in the same module. | ||
| - _Bad_: `types.rs`, `impls.rs` | ||
| - _Good_: `user.rs` containing `struct User` and `impl User`. | ||
|
|
||
| ## 2. Code Structure & Patterns | ||
|
|
||
| ### 2.1 Structs & Types | ||
|
|
||
| - **Small & Cohesive**: Break complex data into smaller, composable structs. | ||
| - **Newtype Pattern**: Use tuple structs (e.g., `pub struct UserId(u64);`) to enforce type safety and prevent argument swapping. | ||
| - **Builder Pattern**: Use for complex initialization logic or structs with many optional fields. Avoid for simple constructors. | ||
| - **Generic Bounds**: Place generic bounds on `impl` blocks or functions, not on the struct definition, unless intrinsic to the type. | ||
|
|
||
| ### 2.2 Async Programming (Tokio) | ||
|
|
||
| - **Runtime**: Use `tokio` as the default async runtime. | ||
| - **Structured Concurrency**: Use `tokio::spawn` for tasks and `tokio::select!` for managing multiple futures. | ||
| - **Synchronization**: | ||
| - Use `tokio::sync::mpsc` for asynchronous message passing. | ||
| - Use `tokio::sync::broadcast` for one-to-many communication. | ||
| - Use `tokio::sync::oneshot` for single responses. | ||
| - Prefer **bounded channels** to manage backpressure. | ||
| - Use `tokio::sync::Mutex` / `RwLock` for shared state in async contexts. | ||
| - **Performance**: Avoid blocking operations in async contexts. Offload CPU-bound work to `tokio::task::spawn_blocking`. | ||
|
|
||
| ### 2.3 Error Handling | ||
|
|
||
| - **Result & Option**: Use `Result<T, E>` for recoverable errors. Use `?` for propagation. | ||
| - **Crates**: Use `thiserror` for library errors and `anyhow` for application-level error handling. | ||
| - **Panic**: Reserve `panic!` for unrecoverable bugs (logic errors). | ||
|
|
||
| ## 3. Performance & Optimization | ||
|
|
||
| - **Collections**: Default to `Vec` and `HashMap`. | ||
| - **Pre-allocation**: Always use `Vec::with_capacity` or `HashMap::with_capacity` when the approximate size is known. | ||
| - **Cloning**: Be mindful of `.clone()`. Use references `&T` where ownership transfer isn't needed. | ||
|
|
||
| ## 4. Testing | ||
|
|
||
| - **Unit Tests**: Place isolated tests in a `tests` module within the same file using `#[cfg(test)]`. | ||
| - **Async Tests**: Use `#[tokio::test]`. | ||
| - **Documentation Tests**: Use `rustdoc` examples in comments (`///`) to ensure documentation matches code behavior. | ||
| - **Mocking**: Use traits to define interfaces, allowing for easier mocking in tests. | ||
|
|
||
| ## 5. Ecosystem & Config | ||
|
|
||
| - **Configuration**: Use environment variables (e.g., `dotenv`) for config management. | ||
| - **Crates**: Prefer standard ecosystem crates: `serde` (serialization), `reqwest` (HTTP), `sqlx` (DB), `tracing` (logging). | ||
|
|
||
| When asked to write code, always apply these rules to ensure the highest quality output. | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| -- Table to track Twitter API usage for the monthly cap | ||
| CREATE TABLE IF NOT EXISTS tweet_pull_usage ( | ||
| period VARCHAR(7) PRIMARY KEY, -- Format: YYYY-MM | ||
| tweet_count INTEGER DEFAULT 0, | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
| ); | ||
|
|
||
| -- Trigger for updated_at | ||
| DROP TRIGGER IF EXISTS set_timestamp ON tweet_pull_usage; | ||
| CREATE TRIGGER set_timestamp | ||
| BEFORE UPDATE ON tweet_pull_usage | ||
| FOR EACH ROW | ||
| EXECUTE PROCEDURE trigger_set_timestamp(); | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # CONFIG ------------------------------------------ | ||
| CONTAINER_NAME="task_master_test_db" # Change if your container is named differently | ||
| DB_USER="postgres" | ||
| DB_NAME="task_master" | ||
| SQL_FILE="seed_authors.sql" | ||
| # -------------------------------------------------- | ||
|
|
||
| echo "🔧 Generating seed SQL..." | ||
|
|
||
| cat << 'EOF' > $SQL_FILE | ||
| INSERT INTO tweet_authors ( | ||
| id, name, username, followers_count, following_count, | ||
| tweet_count, listed_count, like_count, media_count, fetched_at | ||
| ) | ||
| VALUES | ||
| ('1862779229277954048', 'Yuvi Lightman', 'YuviLightman', 0, 0, 0, 0, 0, 0, NOW()) | ||
| ON CONFLICT (id) DO UPDATE SET | ||
| name = EXCLUDED.name, | ||
| username = EXCLUDED.username, | ||
| followers_count = EXCLUDED.followers_count, | ||
| following_count = EXCLUDED.following_count, | ||
| tweet_count = EXCLUDED.tweet_count, | ||
| listed_count = EXCLUDED.listed_count, | ||
| like_count = EXCLUDED.like_count, | ||
| media_count = EXCLUDED.media_count, | ||
| fetched_at = NOW(); | ||
| EOF | ||
|
|
||
| echo "📦 Copying SQL file into container ($CONTAINER_NAME)..." | ||
| podman cp "$SQL_FILE" "$CONTAINER_NAME":/"$SQL_FILE" | ||
|
|
||
| echo "🚀 Running seed script inside Postgres..." | ||
| podman exec -it "$CONTAINER_NAME" psql -U "$DB_USER" -d "$DB_NAME" -f "/$SQL_FILE" | ||
|
|
||
| echo "🔍 Verifying result..." | ||
| podman exec -it "$CONTAINER_NAME" psql -U "$DB_USER" -d "$DB_NAME" -c "SELECT * FROM tweet_authors WHERE id = '1862779229277954048';" | ||
|
|
||
| rm -rf "$SQL_FILE" | ||
|
|
||
| echo "✅ Seeding complete!" |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
| use sqlx::FromRow; | ||
| use chrono::{DateTime, Utc}; | ||
|
|
||
| #[derive(Debug, Clone, Serialize, Deserialize, FromRow)] | ||
| pub struct TweetPullUsage { | ||
| pub period: String, | ||
| pub tweet_count: i32, | ||
| pub updated_at: DateTime<Utc>, | ||
| } | ||
|
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not be checked in