feat(bots): Consolidate bot posting into autonomous module and improve caching
- Remove scheduled posting logic and consolidate all bot posting into autonomous module - Simplify cron endpoint to only call processAllAutonomousBots with cleaner response format - Add background post caching for swarm follow operations via cacheSwarmUserPosts - Update background scheduler to remove scheduled posting references and streamline logging - Improve autonomous module documentation to clarify schedule-based posting with optional sources - Enhance error tracking and reporting across bot task execution - Reduce code duplication by eliminating separate scheduled/autonomous processing paths
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
/**
|
||||
* Cron endpoint for bot scheduled posting
|
||||
* Cron endpoint for bot autonomous posting
|
||||
*
|
||||
* Call this endpoint periodically (e.g., every minute) via cron job or PM2
|
||||
*/
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { processScheduledPosts } from '@/lib/bots/scheduler';
|
||||
import { processAllAutonomousBots } from '@/lib/bots/autonomous';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
@@ -18,23 +17,18 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
// Process scheduled posts
|
||||
const scheduledResult = await processScheduledPosts();
|
||||
|
||||
// Process autonomous bots
|
||||
const autonomousResult = await processAllAutonomousBots();
|
||||
const results = await processAllAutonomousBots();
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
scheduled: {
|
||||
processed: scheduledResult.processed,
|
||||
skipped: scheduledResult.skipped,
|
||||
errors: scheduledResult.errors.length,
|
||||
},
|
||||
autonomous: {
|
||||
total: autonomousResult.length,
|
||||
posted: autonomousResult.filter(r => r.result.posted).length,
|
||||
},
|
||||
total: results.length,
|
||||
posted: results.filter(r => r.result.posted).length,
|
||||
errors: results.filter(r => r.error).length,
|
||||
details: results.map(r => ({
|
||||
handle: r.botHandle,
|
||||
posted: r.result.posted,
|
||||
reason: r.result.reason || r.error,
|
||||
})),
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user