-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathprocessing-service.ts
More file actions
131 lines (108 loc) · 3.29 KB
/
Copy pathprocessing-service.ts
File metadata and controls
131 lines (108 loc) · 3.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { Entity } from './entity'
import { Pipeline, ServerPipeline } from './pipeline'
export type ServerProcessingService = any // TODO: Update this type
export const SERVER_PROCESSING_SERVICE_STATUS_CODES = [
'OFFLINE',
'ONLINE',
'UNKNOWN',
] as const
export type ServerProcessingServiceStatusCode =
(typeof SERVER_PROCESSING_SERVICE_STATUS_CODES)[number]
export enum ProcessingServiceStatusType {
Success,
Error,
Unknown,
}
export class ProcessingService extends Entity {
protected readonly _processingService: ServerProcessingService
protected readonly _pipelines: Pipeline[] = []
public constructor(processingService: ServerProcessingService) {
super(processingService)
this._processingService = processingService
if (processingService.pipelines) {
this._pipelines = processingService.pipelines.map(
(pipeline: ServerPipeline) => new Pipeline(pipeline)
)
}
}
get pipelines(): Pipeline[] {
return this._pipelines
}
get id(): string {
return `${this._processingService.id}`
}
get name(): string {
return `${this._processingService.name}`
}
get endpointUrl(): string | undefined {
const url = this._processingService.endpoint_url
return url && url.trim().length > 0 ? url : undefined
}
get isAsync(): boolean {
return this._processingService.is_async ?? false
}
get description(): string {
return `${this._processingService.description}`
}
get lastSeen(): Date | undefined {
if (!this._processingService.last_seen) {
return undefined
}
return new Date(this._processingService.last_seen)
}
get lastSeenLive(): boolean {
return this._processingService.last_seen_live ?? false
}
get apiKeyPrefix(): string | undefined {
return this._processingService.api_key_prefix ?? undefined
}
get lastSeenClientInfo():
| {
hostname?: string
software?: string
version?: string
platform?: string
ip?: string
user_agent?: string
}
| undefined {
return this._processingService.last_seen_client_info ?? undefined
}
get numPiplinesAdded(): number {
return this._pipelines.length
}
get status(): {
code: ServerProcessingServiceStatusCode
label: string
type: ProcessingServiceStatusType
color: string
} {
if (this.isAsync) {
// Async services derive status from heartbeat
const status_code = this.lastSeenLive ? 'ONLINE' : 'UNKNOWN'
return ProcessingService.getStatusInfo(status_code)
}
const status_code = this.lastSeenLive ? 'ONLINE' : 'OFFLINE'
return ProcessingService.getStatusInfo(status_code)
}
static getStatusInfo(code: ServerProcessingServiceStatusCode) {
const label =
String(code).charAt(0).toUpperCase() + String(code).toLowerCase().slice(1)
const type = {
OFFLINE: ProcessingServiceStatusType.Error,
ONLINE: ProcessingServiceStatusType.Success,
UNKNOWN: ProcessingServiceStatusType.Unknown,
}[code]
const color = {
[ProcessingServiceStatusType.Error]: '#ef4444', // color-destructive-500,
[ProcessingServiceStatusType.Success]: '#09af8a', // color-success-500
[ProcessingServiceStatusType.Unknown]: '#9ca3af', // gray-400
}[type]
return {
code,
label,
type,
color,
}
}
}