Skip to content

Commit 83e0711

Browse files
committed
✨ add job information to inference
1 parent cab4e50 commit 83e0711

File tree

6 files changed

+78
-5
lines changed

6 files changed

+78
-5
lines changed

src/main/java/com/mindee/parsing/v2/Inference.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public class Inference {
2323
@JsonProperty("id")
2424
private String id;
2525

26+
/**
27+
* Job the inference belongs to.
28+
*/
29+
@JsonProperty("job")
30+
private InferenceJob job;
31+
2632
/**
2733
* Model info.
2834
*/
@@ -53,6 +59,8 @@ public String toString() {
5359
joiner
5460
.add("Inference")
5561
.add("#########")
62+
.add(job.toString())
63+
.add("")
5664
.add(model.toString())
5765
.add("")
5866
.add(file.toString())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.mindee.parsing.v2;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import java.util.StringJoiner;
6+
import lombok.AllArgsConstructor;
7+
import lombok.EqualsAndHashCode;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
11+
/**
12+
* Information on the Job associated to a given Inference.
13+
*/
14+
@Getter
15+
@EqualsAndHashCode
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
@AllArgsConstructor
18+
@NoArgsConstructor
19+
public class InferenceJob {
20+
/**
21+
* UUID of the Job.
22+
*/
23+
@JsonProperty("id")
24+
private String id;
25+
26+
public String toString() {
27+
28+
StringJoiner joiner = new StringJoiner("\n");
29+
joiner.add("Job").add("===").add(":ID: " + id);
30+
return joiner.toString();
31+
}
32+
}

src/main/java/com/mindee/parsing/v2/Job.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import lombok.NoArgsConstructor;
1313

1414
/**
15-
* Defines an enqueued Job.
15+
* Information on the processing of a file sent to the Mindee API.
1616
*/
1717

1818
@Getter
@@ -22,12 +22,19 @@
2222
@NoArgsConstructor
2323
public final class Job {
2424
/**
25-
* Date and time the job was created at.
25+
* Date and time of the Job creation.
2626
*/
2727
@JsonProperty("created_at")
2828
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
2929
private LocalDateTime createdAt;
3030

31+
/**
32+
* Date and time of the Job completion. Filled once processing is finished.
33+
*/
34+
@JsonProperty("completed_at")
35+
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
36+
private LocalDateTime completedAt;
37+
3138
/**
3239
* ID of the job.
3340
*/

src/test/java/com/mindee/parsing/v2/InferenceTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ void asyncPredict_whenComplete_mustExposeAllProperties() throws IOException {
107107
assertNotNull(inference);
108108
assertEquals("12345678-1234-1234-1234-123456789abc", inference.getId());
109109

110+
InferenceJob job = inference.getJob();
111+
assertEquals("12345678-1234-1234-1234-jobid1234567", job.getId());
112+
110113
InferenceModel model = inference.getModel();
111114
assertNotNull(model, "Model must not be null");
112115
assertEquals("12345678-1234-1234-1234-123456789abc", model.getId());

src/test/java/com/mindee/parsing/v2/JobTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,35 @@ private JobResponse loadJob(String filePath) throws IOException {
1919
}
2020

2121
@Nested
22-
@DisplayName("When the Job is OK")
23-
class OkTest {
22+
@DisplayName("When the Job is processing")
23+
class ProcessingTest {
2424
@Test
2525
@DisplayName("properties must be valid")
2626
void whenProcessing_mustHaveValidProperties() throws IOException {
2727
JobResponse response = loadJob("job/ok_processing.json");
2828
Job job = response.getJob();
2929
assertNotNull(job);
3030
assertEquals("Processing", job.getStatus());
31+
assertNotNull(job.getCreatedAt());
32+
assertNull(job.getCompletedAt());
33+
assertNull(job.getResultUrl());
34+
assertNull(job.getError());
35+
}
36+
}
37+
38+
@Nested
39+
@DisplayName("When the Job is processed")
40+
class ProcessedTest {
41+
@Test
42+
@DisplayName("properties must be valid")
43+
void whenProcessing_mustHaveValidProperties() throws IOException {
44+
JobResponse response = loadJob("job/ok_processed_webhooks_ok.json");
45+
Job job = response.getJob();
46+
assertNotNull(job);
47+
assertEquals("Processed", job.getStatus());
48+
assertNotNull(job.getCreatedAt());
49+
assertNotNull(job.getCompletedAt());
50+
assertNotNull(job.getResultUrl());
3151
assertNull(job.getError());
3252
}
3353
}
@@ -41,6 +61,9 @@ void when422_mustHaveValidProperties() throws IOException {
4161
JobResponse response = loadJob("job/fail_422.json");
4262
Job job = response.getJob();
4363
assertNotNull(job);
64+
assertNotNull(job.getCreatedAt());
65+
assertNotNull(job.getCompletedAt());
66+
assertNull(job.getResultUrl());
4467
ErrorResponse jobError = job.getError();
4568
assertNotNull(jobError);
4669
assertEquals(422, jobError.getStatus());

0 commit comments

Comments
 (0)