Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt

Use this file to discover all available pages before exploring further.

The SDK provides methods to retrieve job status and cancel jobs for async operations.
The Go SDK does not currently support listing all jobs. Use the REST API directly for that feature.

Retrieve Job Status

// Start an async job
jobResponse, err := client.Parse.RunJob(context.Background(), reducto.ParseRunJobParams{
    DocumentURL: reducto.F[reducto.ParseRunJobParamsDocumentURLUnion](
        shared.UnionString(upload.FileID),
    ),
})
if err != nil {
    return err
}

jobID := jobResponse.JobID

// Retrieve job status
job, err := client.Job.Get(context.Background(), jobID)
if err != nil {
    return err
}

// Check status
switch job.Status {
case reducto.JobGetResponseStatusCompleted:
    fmt.Println("Job completed!")
    result := job.Result
    // Access result based on job type
case reducto.JobGetResponseStatusPending:
    fmt.Printf("Job still processing... Progress: %.0f%%\n", job.Progress)
case reducto.JobGetResponseStatusFailed:
    fmt.Printf("Job failed: %s\n", job.Reason)
}

Polling for Completion

import "time"

func waitForJob(ctx context.Context, client *reducto.Client, jobID string) (*reducto.JobGetResponse, error) {
    ticker := time.NewTicker(2 * time.Second)
    defer ticker.Stop()
    
    for {
        select {
        case <-ctx.Done():
            return nil, ctx.Err()
        case <-ticker.C:
            job, err := client.Job.Get(ctx, jobID)
            if err != nil {
                return nil, err
            }
            
            if job.Status == reducto.JobGetResponseStatusCompleted {
                return job, nil
            } else if job.Status == reducto.JobGetResponseStatusFailed {
                return nil, fmt.Errorf("job failed: %s", job.Reason)
            }
            
            fmt.Printf("Status: %s, Progress: %.0f%%\n", job.Status, job.Progress)
        }
    }
}

// Usage
jobResponse, _ := client.Parse.RunJob(context.Background(), params)
job, _ := waitForJob(context.Background(), client, jobResponse.JobID)
result := job.Result

Cancel a Job

// Cancel a running job
_, err := client.Job.Cancel(context.Background(), jobID)
if err != nil {
    return err
}
fmt.Println("Job cancelled")

Method Signatures

// Get job status
func (s *JobService) Get(
    ctx context.Context,
    jobID string,
    opts ...option.RequestOption,
) (*JobGetResponse, error)

// Cancel job
func (s *JobService) Cancel(
    ctx context.Context,
    jobID string,
    opts ...option.RequestOption,
) (*JobCancelResponse, error)

Next Steps