@kumori/aurora-backend-handler 1.1.49 → 1.1.51

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.
@@ -179,19 +179,20 @@ const getContainerError = (
179
179
  };
180
180
 
181
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
- };
182
+ for (const roleData of Object.values<any>(revisionStatus.runtime.roles)) {
183
+ for (const instanceData of Object.values<any>(roleData.instances)) {
184
+ for (const container of Object.values<any>(instanceData.containers ?? {})) {
185
+ if (!container.status.ready) {
186
+ return {
187
+ code: container.status.status.waiting?.reason ?? "ContainerNotReady",
188
+ message: container.status.status.waiting?.message ?? "One or more containers are not ready for unknown reasons.",
189
+ timestamp: Date.now().toString(),
190
+ };
191
+ }
192
+ }
193
+ }
188
194
  }
189
195
 
190
- const containerError = getContainerError(revisionStatus);
191
- if (containerError) return containerError;
192
- if (revisionStatus?.runtime?.status) {
193
- return revisionStatus.runtime.status;
194
- }
195
196
  return revisionStatus?.state;
196
197
  };
197
198
 
@@ -201,9 +202,7 @@ const createRevision = (
201
202
  usedCpu: number,
202
203
  usedMemory: number,
203
204
  ): Revision => {
204
- const status = handleRevisionStatus(eventData.status);
205
- const explicitError = eventData.status?.error;
206
- const containerError = !explicitError ? getContainerError(eventData.status) : null;
205
+ const containerError = eventData.status?.error ? null : getContainerError(eventData.status);
207
206
 
208
207
  return {
209
208
  id: entityId,
@@ -239,9 +238,9 @@ const createRevision = (
239
238
  },
240
239
  cost: 0,
241
240
  },
242
- status,
243
- errorCode: explicitError ? explicitError.code : containerError ? containerError.code : "",
244
- errorMsg: explicitError ? explicitError.message : containerError ? containerError.message : "",
241
+ status: handleRevisionStatus(eventData.status),
242
+ errorCode: eventData.status?.error ? eventData.status.error.code : containerError?.code ?? "",
243
+ errorMsg: eventData.status?.error ? eventData.status.error.message : containerError?.message ?? "",
245
244
  createdAt:
246
245
  (eventData.status && eventData.status.runtime?.status?.createdAt) || "",
247
246
  };
@@ -123,59 +123,40 @@ const determineFinalStatusAndError = (
123
123
  eventData: any,
124
124
  pendingRevisionErrors: Array<{ service: string; revision: Revision }>,
125
125
  entityId: string,
126
- currentRevision: Revision | undefined,
127
126
  ): {
128
127
  finalStatus: any;
129
128
  finalError: any;
130
129
  pendingErrorIndex: number;
131
130
  } => {
132
- const incomingServiceStatus = eventData.status.state;
133
- const incomingTs = getTimestamp(incomingServiceStatus.timestamp);
131
+ const incomingStatus = eventData.status.state;
132
+ const incomingTs = getTimestamp(incomingStatus.timestamp);
134
133
  const currentTs = getTimestamp(existingService?.status?.timestamp);
134
+
135
135
  const isNewer = !existingService || incomingTs > currentTs;
136
+ let finalStatus = existingService?.status;
137
+ let finalError = existingService?.error;
138
+
139
+ if (isNewer) {
140
+ finalStatus = incomingStatus;
141
+ finalError = eventData.status.error ?? undefined;
142
+ }
136
143
 
137
144
  const pendingErrorIndex = pendingRevisionErrors.findIndex(
138
145
  (pending) => pending.service === entityId,
139
146
  );
140
- const pendingError =
141
- pendingErrorIndex !== -1 ? pendingRevisionErrors[pendingErrorIndex] : null;
142
- const serviceError = isNewer ? eventData.status.error : undefined;
143
- const revisionError =
144
- currentRevision?.errorCode
145
- ? {
146
- code: currentRevision.errorCode,
147
- message: currentRevision.errorMsg || "",
148
- timestamp: currentRevision.status?.timestamp || "",
149
- }
150
- : null;
151
-
152
- if (serviceError) {
153
- return { finalStatus: incomingServiceStatus, finalError: serviceError, pendingErrorIndex };
154
- }
155
147
 
156
- if (revisionError) {
157
- return { finalStatus: currentRevision!.status, finalError: revisionError, pendingErrorIndex };
158
- }
159
-
160
- if (pendingError) {
161
- return {
162
- finalStatus: pendingError.revision.status,
163
- finalError: {
164
- code: pendingError.revision.errorCode || "",
165
- message: pendingError.revision.errorMsg || "",
166
- timestamp: pendingError.revision.status?.timestamp || "",
167
- },
168
- pendingErrorIndex,
148
+ if (pendingErrorIndex !== -1) {
149
+ const pendingError = pendingRevisionErrors[pendingErrorIndex];
150
+
151
+ finalStatus = pendingError.revision.status;
152
+ finalError = {
153
+ code: pendingError.revision.errorCode || "",
154
+ message: pendingError.revision.errorMsg || "",
155
+ timestamp: pendingError.revision.status.timestamp || "",
169
156
  };
170
157
  }
171
- if (currentRevision?.status && isNewer) {
172
- return { finalStatus: currentRevision.status, finalError: undefined, pendingErrorIndex };
173
- }
174
- if (isNewer) {
175
- return { finalStatus: incomingServiceStatus, finalError: undefined, pendingErrorIndex };
176
- }
177
158
 
178
- return { finalStatus: existingService?.status, finalError: existingService?.error, pendingErrorIndex };
159
+ return { finalStatus, finalError, pendingErrorIndex };
179
160
  };
180
161
 
181
162
  export const handleServiceEvent = ({
@@ -214,7 +195,6 @@ export const handleServiceEvent = ({
214
195
  eventData,
215
196
  pendingRevisionErrors,
216
197
  entityId,
217
- currentRevision,
218
198
  );
219
199
 
220
200
  const updatedPendingRevisionErrors = [...pendingRevisionErrors];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumori/aurora-backend-handler",
3
- "version": "1.1.49",
3
+ "version": "1.1.51",
4
4
  "description": "backend handler",
5
5
  "main": "backend-handler.ts",
6
6
  "scripts": {