@kumori/aurora-backend-handler 1.1.48 → 1.1.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -159,12 +159,50 @@ const processRolesAndInstances = (
159
159
  return { roles, instances, usedCpu, usedMemory };
160
160
  };
161
161
 
162
+ const getContainerError = (
163
+ revisionStatus: any,
164
+ ): { code: string; message: string; timestamp: string } | null => {
165
+ for (const roleData of Object.values<any>(revisionStatus?.runtime?.roles ?? {})) {
166
+ for (const instanceData of Object.values<any>(roleData.instances ?? {})) {
167
+ for (const container of Object.values<any>(instanceData.containers ?? {})) {
168
+ if (!container.status.ready) {
169
+ return {
170
+ code: container.status.status.waiting?.reason ?? "ContainerNotReady",
171
+ message: container.status.status.waiting?.message ?? "One or more containers are not ready for unknown reasons.",
172
+ timestamp: Date.now().toString(),
173
+ };
174
+ }
175
+ }
176
+ }
177
+ }
178
+ return null;
179
+ };
180
+
181
+ const handleRevisionStatus = (revisionStatus: any) => {
182
+ if (revisionStatus?.error) {
183
+ return {
184
+ code: revisionStatus.error.code,
185
+ message: revisionStatus.error.message,
186
+ timestamp: Date.now().toString(),
187
+ };
188
+ }
189
+
190
+ const containerError = getContainerError(revisionStatus);
191
+ if (containerError) return containerError;
192
+
193
+ return revisionStatus?.state;
194
+ };
195
+
162
196
  const createRevision = (
163
197
  entityId: string,
164
198
  eventData: any,
165
199
  usedCpu: number,
166
200
  usedMemory: number,
167
201
  ): Revision => {
202
+ const status = handleRevisionStatus(eventData.status);
203
+ const explicitError = eventData.status?.error;
204
+ const containerError = !explicitError ? getContainerError(eventData.status) : null;
205
+
168
206
  return {
169
207
  id: entityId,
170
208
  schema: {},
@@ -199,30 +237,13 @@ const createRevision = (
199
237
  },
200
238
  cost: 0,
201
239
  },
202
- status: handleRevisionStatus(eventData.status),
203
- errorCode: eventData.status?.error ? eventData.status.error.code : handleRevisionStatus(eventData.status)?.code === "CrashLoopBackOff" ? handleRevisionStatus(eventData.status)?.code : "",
204
- errorMsg: eventData.status?.error ? eventData.status.error.message : handleRevisionStatus(eventData.status)?.code === "CrashLoopBackOff" ? handleRevisionStatus(eventData.status)?.message : "",
240
+ status,
241
+ errorCode: explicitError ? explicitError.code : containerError ? containerError.code : "",
242
+ errorMsg: explicitError ? explicitError.message : containerError ? containerError.message : "",
205
243
  createdAt:
206
244
  (eventData.status && eventData.status.runtime?.status?.createdAt) || "",
207
245
  };
208
246
  };
209
- const handleRevisionStatus = (revisionStatus: any) => {
210
- for (const roleData of Object.values<any>(revisionStatus.runtime.roles)) {
211
- for (const instanceData of Object.values<any>(roleData.instances)) {
212
- for (const container of Object.values<any>(instanceData.containers ?? {})) {
213
- if (!container.status.ready) {
214
- return {
215
- code: container.status.status.waiting?.reason ?? "ContainerNotReady",
216
- message: container.status.status.waiting?.message ?? "One or more containers are not ready for unknown reasons.",
217
- timestamp: Date.now().toString(),
218
- };
219
- }
220
- }
221
- }
222
- }
223
-
224
- return revisionStatus?.state;
225
- };
226
247
  const updateServiceWithRevision = (
227
248
  existingService: Service,
228
249
  entityId: string,
@@ -138,11 +138,7 @@ const determineFinalStatusAndError = (
138
138
 
139
139
  if (isNewer) {
140
140
  finalStatus = incomingStatus;
141
- if (eventData.status.error) {
142
- finalError = eventData.status.error;
143
- } else {
144
- finalError = undefined;
145
- }
141
+ finalError = eventData.status.error ?? undefined;
146
142
  }
147
143
 
148
144
  const pendingErrorIndex = pendingRevisionErrors.findIndex(
@@ -151,17 +147,13 @@ const determineFinalStatusAndError = (
151
147
 
152
148
  if (pendingErrorIndex !== -1) {
153
149
  const pendingError = pendingRevisionErrors[pendingErrorIndex];
154
- const pendingTs = getTimestamp(pendingError.revision.status.timestamp);
155
- const currentDecisionTs = getTimestamp(finalStatus?.timestamp);
156
-
157
- if (pendingTs > currentDecisionTs) {
158
- finalStatus = pendingError.revision.status;
159
- finalError = {
160
- code: pendingError.revision.errorCode || "",
161
- message: pendingError.revision.errorMsg || "",
162
- timestamp: pendingError.revision.status.timestamp || "",
163
- };
164
- }
150
+
151
+ finalStatus = pendingError.revision.status;
152
+ finalError = {
153
+ code: pendingError.revision.errorCode || "",
154
+ message: pendingError.revision.errorMsg || "",
155
+ timestamp: pendingError.revision.status.timestamp || "",
156
+ };
165
157
  }
166
158
 
167
159
  return { finalStatus, finalError, pendingErrorIndex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.48",
3
+ "version": "1.1.50",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {