Skip to content

Commit

Permalink
fix: Differentiate between pending in db and in redis in admin job stats
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Apr 11, 2024
1 parent 95cf8f4 commit cf0df0e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
18 changes: 11 additions & 7 deletions apps/web/app/dashboard/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,28 @@ function ServerStatsSection() {
<Table className="lg:w-1/2">
<TableHeader>
<TableHead>Job</TableHead>
<TableHead>Queued</TableHead>
<TableHead>Pending</TableHead>
<TableHead>Failed</TableHead>
</TableHeader>
<TableBody>
<TableRow>
<TableCell className="lg:w-2/3">Crawling Jobs</TableCell>
<TableCell>{serverStats.pendingCrawls}</TableCell>
<TableCell>{serverStats.failedCrawls}</TableCell>
<TableCell>{serverStats.crawlStats.queuedInRedis}</TableCell>
<TableCell>{serverStats.crawlStats.pending}</TableCell>
<TableCell>{serverStats.crawlStats.failed}</TableCell>
</TableRow>
<TableRow>
<TableCell>Indexing Jobs</TableCell>
<TableCell>{serverStats.pendingIndexing}</TableCell>
<TableCell>{serverStats.failedIndexing}</TableCell>
<TableCell>{serverStats.indexingStats.queuedInRedis}</TableCell>
<TableCell>-</TableCell>
<TableCell>-</TableCell>
</TableRow>
<TableRow>
<TableCell>OpenAI Jobs</TableCell>
<TableCell>{serverStats.pendingOpenai}</TableCell>
<TableCell>{serverStats.failedOpenai}</TableCell>
<TableCell>Inference Jobs</TableCell>
<TableCell>{serverStats.inferenceStats.queuedInRedis}</TableCell>
<TableCell>{serverStats.inferenceStats.pending}</TableCell>
<TableCell>{serverStats.inferenceStats.failed}</TableCell>
</TableRow>
</TableBody>
</Table>
Expand Down
2 changes: 1 addition & 1 deletion apps/workers/searchWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class SearchIndexingWorker {

worker.on("failed", (job, error) => {
const jobId = job?.id ?? "unknown";
logger.error(`[search][${jobId}] openai job failed: ${error}`);
logger.error(`[search][${jobId}] search job failed: ${error}`);
});

return worker;
Expand Down
70 changes: 52 additions & 18 deletions packages/trpc/routers/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,44 @@ export const adminAppRouter = router({
z.object({
numUsers: z.number(),
numBookmarks: z.number(),
pendingCrawls: z.number(),
failedCrawls: z.number(),
pendingIndexing: z.number(),
failedIndexing: z.number(),
pendingOpenai: z.number(),
failedOpenai: z.number(),
crawlStats: z.object({
queuedInRedis: z.number(),
pending: z.number(),
failed: z.number(),
}),
inferenceStats: z.object({
queuedInRedis: z.number(),
pending: z.number(),
failed: z.number(),
}),
indexingStats: z.object({
queuedInRedis: z.number(),
}),
}),
)
.query(async ({ ctx }) => {
const [
[{ value: numUsers }],
[{ value: numBookmarks }],

// Crawls
pendingCrawlsInRedis,
[{ value: pendingCrawls }],
[{ value: failedCrawls }],
pendingIndexing,
failedIndexing,
pendingOpenai,
failedOpenai,

// Indexing
pendingIndexingInRedis,

// Inference
pendingInferenceInRedis,
[{ value: pendingInference }],
[{ value: failedInference }],
] = await Promise.all([
ctx.db.select({ value: count() }).from(users),
ctx.db.select({ value: count() }).from(bookmarks),

// Crawls
LinkCrawlerQueue.getWaitingCount(),
ctx.db
.select({ value: count() })
.from(bookmarkLinks)
Expand All @@ -45,21 +62,38 @@ export const adminAppRouter = router({
.select({ value: count() })
.from(bookmarkLinks)
.where(eq(bookmarkLinks.crawlStatus, "failure")),

// Indexing
SearchIndexingQueue.getWaitingCount(),
SearchIndexingQueue.getFailedCount(),

// Inference
OpenAIQueue.getWaitingCount(),
OpenAIQueue.getFailedCount(),
ctx.db
.select({ value: count() })
.from(bookmarks)
.where(eq(bookmarks.taggingStatus, "pending")),
ctx.db
.select({ value: count() })
.from(bookmarks)
.where(eq(bookmarks.taggingStatus, "failure")),
]);

return {
numUsers,
numBookmarks,
pendingCrawls,
failedCrawls,
pendingIndexing,
failedIndexing,
pendingOpenai,
failedOpenai,
crawlStats: {
queuedInRedis: pendingCrawlsInRedis,
pending: pendingCrawls,
failed: failedCrawls,
},
inferenceStats: {
queuedInRedis: pendingInferenceInRedis,
pending: pendingInference,
failed: failedInference,
},
indexingStats: {
queuedInRedis: pendingIndexingInRedis,
},
};
}),
recrawlLinks: adminProcedure
Expand Down

0 comments on commit cf0df0e

Please sign in to comment.