-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexample-grpc-service.ts
More file actions
88 lines (82 loc) · 2.29 KB
/
example-grpc-service.ts
File metadata and controls
88 lines (82 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Example gRPC service implementation using the proto-defined JobDataService.
*
* This demonstrates how to implement a gRPC service that can be registered
* with the proto plugin and accessed by clients (browser via Connect,
* or native gRPC from Python/Go).
*
* Usage:
* import { proto } from "@databricks/appkit";
* import { jobDataServiceImpl } from "./example-grpc-service";
* import { JobDataService } from "shared/proto/appkit/v1/services_pb";
*
* const appkit = await createApp({
* plugins: [
* proto({
* services: [{ service: JobDataService, implementation: jobDataServiceImpl }],
* }),
* ],
* });
*/
import type { JobStatus } from "shared";
// Example in-memory store for job results
const mockJobResults = new Map<
string,
{
jobRunId: string;
jobId: string;
status: number;
rows: Array<{ fields: Record<string, { case: string; value: unknown }> }>;
}
>();
// Seed some mock data
mockJobResults.set("run-001", {
jobRunId: "run-001",
jobId: "job-pipeline-etl",
status: 3, // SUCCESS
rows: [
{
fields: {
name: { case: "stringValue", value: "Alice" },
score: { case: "numberValue", value: 95.5 },
passed: { case: "boolValue", value: true },
},
},
{
fields: {
name: { case: "stringValue", value: "Bob" },
score: { case: "numberValue", value: 82.3 },
passed: { case: "boolValue", value: true },
},
},
],
});
/**
* Example implementation of the JobDataService.
*
* In production, this would query Databricks Jobs API or read
* proto-serialized results from UC Volumes.
*/
export const jobDataServiceImpl = {
async getJobResult(request: { jobRunId: string }) {
const result = mockJobResults.get(request.jobRunId);
if (!result) {
throw new Error(`Job run "${request.jobRunId}" not found`);
}
return result;
},
async *streamJobResults(request: { jobId: string }) {
// Stream all results matching the job ID
for (const [, result] of mockJobResults) {
if (result.jobId === request.jobId) {
yield result;
}
}
},
async submitBatch(request: { batch?: { batchId: string } }) {
return {
accepted: true,
batchId: request.batch?.batchId ?? "generated-batch-id",
};
},
};