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:
Christomatt
2026-01-26 09:39:12 +01:00
parent 731838dd48
commit e98221e81a
6 changed files with 354 additions and 193 deletions
+10 -16
View File
@@ -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) {