import com.newscatcher.catchall.CatchAllApi;
import com.newscatcher.catchall.resources.jobs.requests.SubmitRequestDto;
import com.newscatcher.catchall.types.StatusResponseDto;
import com.newscatcher.catchall.types.PullJobResponseDto;
public class JobsExample {
public static void main(String[] args) throws InterruptedException {
CatchAllApi client = CatchAllApi.builder()
.apiKey("YOUR_API_KEY")
.build();
// Create a job
var job = client.jobs().createJob(
SubmitRequestDto.builder()
.query("Tech company earnings this quarter")
.context("Focus on revenue and profit margins")
.schema("Company [NAME] earned [REVENUE] in [QUARTER]")
.build()
);
System.out.println("Job created: " + job.getJobId());
// Poll for completion
String jobId = job.getJobId();
while (true) {
StatusResponseDto status = client.jobs().getJobStatus(jobId);
if ("job_completed".equals(status.getStatus())) {
System.out.println("Job completed!");
break;
}
Thread.sleep(60000); // Wait 60 seconds
}
// Retrieve results
PullJobResponseDto results = client.jobs().getJobResults(jobId);
System.out.println(String.format(
"Found %d valid records",
results.getValidRecords()
));
results.getAllRecords().forEach(record ->
System.out.println(record.getRecordTitle())
);
}
}