-
Notifications
You must be signed in to change notification settings - Fork 8
Generate Post via Task #120
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe changes implement an asynchronous workflow for blog post content generation, replacing synchronous processing with a task queue-based system. Updates span backend task definitions, status polling endpoints, frontend task persistence and polling, email notifications, and supporting schema/choice definitions. Changes
Sequence DiagramssequenceDiagram
participant User
participant Frontend as Frontend<br/>(generate-content)
participant API as Backend API
participant TaskQueue as Task Queue<br/>(django-q)
participant Email as Email Service
User->>Frontend: Click "Generate Post"
Frontend->>API: POST /api/generate-blog-content
API->>TaskQueue: Queue async_task:<br/>generate_blog_post_content
API-->>Frontend: {"status": "processing", "task_id": "xyz"}
Frontend->>Frontend: Store task_id in localStorage
Frontend->>Frontend: Start polling loop
loop Polling (every N seconds)
Frontend->>API: GET /api/task-status/xyz
API->>TaskQueue: Fetch Task status
alt Task Processing
API-->>Frontend: {"status": "processing"}
Frontend->>Frontend: Update elapsed time
else Task Complete
TaskQueue->>TaskQueue: generate_blog_post_content executes
TaskQueue->>Email: Queue send_blog_post_ready_email
Email->>Email: Render & send notification
API-->>Frontend: {"status": "completed",<br/>"blog_post_id": 123}
Frontend->>Frontend: _updateToCompletedState
Frontend->>Frontend: Clear localStorage
Frontend->>Frontend: Stop polling
else Task Failed
API-->>Frontend: {"status": "failed"}
Frontend->>Frontend: _resetToInitialState
end
end
Frontend->>User: Show completion status & link
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (8)
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. Comment |
Greptile OverviewGreptile SummaryConverted blog post generation from synchronous to asynchronous task-based execution with client-side polling. Users can now navigate away during generation and receive email notifications when complete. Key changes:
Issues found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Browser
participant API as Django API
participant Queue as django-q2
participant Task as generate_blog_post_content
participant Email as Email Service
User->>Browser: Click "Generate" button
Browser->>Browser: Store taskId in localStorage
Browser->>API: POST /api/generate-blog-content/{id}
API->>Queue: Queue task with suggestion_id
Queue-->>API: Return task_id
API-->>Browser: {status: "processing", task_id}
Browser->>Browser: Show "Generating..." state
loop Poll every 3 seconds (max 5 min)
Browser->>API: GET /api/task-status/{task_id}
API->>Queue: Check task result
alt Task still processing
Queue-->>API: None (not complete)
API-->>Browser: {status: "processing"}
Browser->>Browser: Update elapsed time display
else Task completed
Queue-->>API: Task result
API->>API: Fetch blog post from DB
API-->>Browser: {status: "completed", blog_post_id, content}
Browser->>Browser: Clear localStorage
Browser->>Browser: Show "View Post" button
Browser->>User: Show success message
end
end
Note over Queue,Task: Background execution (2-5 minutes)
Queue->>Task: Execute async task
Task->>Task: suggestion.generate_content()
Task->>Task: Blog post created
alt send_email=True (manual generation)
Task->>Queue: Queue email notification
Queue->>Email: Send blog_post_ready email
Email->>User: Email notification
end
Task-->>Queue: Return success message
|
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.
Additional Comments (2)
-
core/tasks.py, line 477-479 (link)logic:
generate_and_post_blog_poststill uses synchronous generation, not the new task-based approachThis will block the worker for 2-5 minutes. Use the new
generate_blog_post_contenttask withsend_email=False: -
core/tasks.py, line 490-492 (link)logic:
generate_and_post_blog_poststill uses synchronous generationUse the new task with
send_email=False:
8 files reviewed, 4 comments
| task = Task.objects.get(id=task_id) | ||
| suggestion_id = task.args[0] if task.args else None |
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.
logic: missing authorization check - user could access another user's task
Verify task belongs to requesting user:
| task = Task.objects.get(id=task_id) | |
| suggestion_id = task.args[0] if task.args else None | |
| try: | |
| task = Task.objects.get(id=task_id) | |
| suggestion_id = task.args[0] if task.args else None |
Prompt To Fix With AI
This is a comment left during a code review.
Path: core/api/views.py
Line: 476:477
Comment:
**logic:** missing authorization check - user could access another user's task
Verify task belongs to requesting user:
```suggestion
try:
task = Task.objects.get(id=task_id)
suggestion_id = task.args[0] if task.args else None
```
How can I resolve this? If you propose a fix, please make it concise.| async _pollTaskStatus(taskId) { | ||
| const pollInterval = 3000; // Poll every 3 seconds | ||
| const initialDelay = 2000; // Wait 2 seconds before first poll | ||
| const maxAttempts = 100; // 5 minutes maximum (100 * 3 seconds) |
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.
style: 5 minutes (100 attempts × 3 seconds) may be insufficient given the stated 2-5 minute generation time plus DB polling delays
Consider increasing to 120 attempts (6 minutes) to provide buffer:
| const maxAttempts = 100; // 5 minutes maximum (100 * 3 seconds) | |
| const maxAttempts = 120; // 6 minutes maximum (120 * 3 seconds) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/src/controllers/generate-content-controller.js
Line: 174:174
Comment:
**style:** 5 minutes (100 attempts × 3 seconds) may be insufficient given the stated 2-5 minute generation time plus DB polling delays
Consider increasing to 120 attempts (6 minutes) to provide buffer:
```suggestion
const maxAttempts = 120; // 6 minutes maximum (120 * 3 seconds)
```
How can I resolve this? If you propose a fix, please make it concise.
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.