Poll for Completion
Content: Poll for Completion
User Intent
"I want to know when content processing has finished"
Operation
SDK Method:
graphlit.isContentDone()GraphQL:
isContentDonequeryEntity Type: Content
Common Use Cases: Wait for async ingestion, check processing status
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
import { Types } from 'graphlit-client/dist/generated/graphql-types';
const graphlit = new Graphlit();
// After async ingestion
const contentResponse = await graphlit.ingestUri(
'https://example.com/document.pdf',
undefined, undefined, undefined,
false // isSynchronous = false (async)
);
const contentId = contentResponse.ingestUri.id;
console.log('Content ingestion started, polling for completion...');
// Poll for completion
let isDone = false;
let attempts = 0;
const maxAttempts = 60; // 10 minutes max
while (!isDone && attempts < maxAttempts) {
const status = await graphlit.isContentDone(contentId);
isDone = status.isContentDone.result || false;
if (!isDone) {
attempts++;
console.log(`Still processing... (${attempts}/${maxAttempts})`);
await new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 seconds
}
}
if (isDone) {
console.log(' Content processing complete!');
// Now safe to access content
const content = await graphlit.getContent(contentId);
console.log(`Extracted ${content.content.markdown?.length || 0} chars`);
} else {
console.log('⏰ Timeout - still processing');
}After async ingestion
content_response = await graphlit.ingestUri( uri="https://example.com/document.pdf", is_synchronous=False )
content_id = content_response.ingest_uri.id
Poll for completion (snake_case)
is_done = False attempts = 0 max_attempts = 60
while not is_done and attempts < max_attempts: status = await graphlit.isContentDone(content_id) is_done = status.is_content_done.result if status.is_content_done else False
if not is_done:
attempts += 1
print(f"Still processing... ({attempts}/{max_attempts})")
await asyncio.sleep(10)if is_done: print(" Content processing complete!")
**C#**:
```csharp
using Graphlit;
using System.Threading.Tasks;
var client = new Graphlit();
// After async ingestion
var contentResponse = await graphlit.IngestUri(
uri: "https://example.com/document.pdf",
isSynchronous: false
);
var contentId = contentResponse.IngestUri.Id;
// Poll for completion (PascalCase)
bool isDone = false;
int attempts = 0;
int maxAttempts = 60;
while (!isDone && attempts < maxAttempts)
{
var status = await graphlit.IsContentDone(contentId);
isDone = status.IsContentDone?.Result ?? false;
if (!isDone)
{
attempts++;
Console.WriteLine($"Still processing... ({attempts}/{maxAttempts})");
await Task.Delay(10000); // Wait 10 seconds
}
}
if (isDone)
{
Console.WriteLine(" Content processing complete!");
}Parameters
id(string): Content ID to check
Response
{
isContentDone: {
result: boolean; // true = complete, false = still processing
}
}Developer Hints
Async vs Sync Ingestion
// Synchronous - waits automatically
const content = await graphlit.ingestUri(uri, undefined, undefined, undefined, true);
// Content ready immediately
// Asynchronous - need to poll
const content = await graphlit.ingestUri(uri, undefined, undefined, undefined, false);
// Poll with isContentDone()Polling Helper Function
async function waitForContent(
contentId: string,
timeoutMinutes: number = 10
): Promise<boolean> {
const maxAttempts = timeoutMinutes * 6; // 6 checks per minute
let attempts = 0;
while (attempts < maxAttempts) {
const status = await graphlit.isContentDone(contentId);
if (status.isContentDone.result) {
return true;
}
attempts++;
await new Promise(resolve => setTimeout(resolve, 10000));
}
return false; // Timeout
}
// Usage
const done = await waitForContent(contentId, 10);
if (done) {
console.log('Ready!');
}Last updated
Was this helpful?