Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 8af20a1

Browse files
authored
fix(orchestrator): return instance ID also on failed execute workflow API call (backport 1.3) (#2525)
fix(orchestrator): Return instance ID also on failed execute workflow API call
1 parent 358dbfd commit 8af20a1

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

.changeset/great-keys-sing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

plugins/orchestrator-backend/src/service/SonataFlowService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('SonataFlowService', () => {
167167
);
168168
expect(result).toEqual({ id: definitionId, status: 'completed' });
169169
expect(loggerMock.debug).toHaveBeenCalledWith(
170-
`Execute workflow result: {"id":"${definitionId}","status":"completed"}`,
170+
'Execute workflow successful. Response: {"id":"workflow-123","status":"completed"}',
171171
);
172172
// Verify that all other logger methods were not called
173173
expect(loggerMock.debug).toHaveBeenCalledTimes(1);

plugins/orchestrator-backend/src/service/SonataFlowService.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,28 @@ export class SonataFlowService {
8989
headers: { 'content-type': 'application/json' },
9090
});
9191

92-
if (response.ok) {
93-
const json = await response.json();
94-
this.logger.debug(`Execute workflow result: ${JSON.stringify(json)}`);
92+
const json = await response.json();
93+
if (json.id) {
94+
this.logger.debug(
95+
`Execute workflow successful. Response: ${JSON.stringify(json)}`,
96+
);
9597
return json;
98+
} else if (!response.ok) {
99+
const errorMessage = await this.createPrefixFetchErrorMessage(
100+
urlToFetch,
101+
response,
102+
'POST',
103+
);
104+
this.logger.error(
105+
`Execute workflow failed. Response: ${JSON.stringify(json)}`,
106+
);
107+
throw new Error(errorMessage);
108+
} else {
109+
this.logger.error(
110+
`Execute workflow did not return a workflow instance ID. Response: ${JSON.stringify(json)}`,
111+
);
112+
throw new Error('Execute workflow did not return a workflow instance ID');
96113
}
97-
throw new Error(
98-
`${await this.createPrefixFetchErrorMessage(urlToFetch, response, 'POST')}`,
99-
);
100114
}
101115

102116
public async fetchWorkflowOverview(

plugins/orchestrator-backend/src/service/WorkflowCacheService.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,26 @@ export class WorkflowCacheService {
7373
});
7474
await Promise.all(
7575
Object.entries(idUrlMap).map(async ([definitionId, serviceUrl]) => {
76-
const isServiceUp = await this.sonataFlowService.pingWorkflowService({
77-
definitionId,
78-
serviceUrl,
79-
});
76+
let isServiceUp = false;
77+
try {
78+
isServiceUp = await this.sonataFlowService.pingWorkflowService({
79+
definitionId,
80+
serviceUrl,
81+
});
82+
} catch (err) {
83+
this.logger.error(
84+
`Ping workflow ${definitionId} service threw error: ${err}`,
85+
);
86+
}
8087
if (isServiceUp) {
8188
this.definitionIdCache.add(definitionId);
82-
} else if (this.definitionIdCache.has(definitionId)) {
89+
} else {
8390
this.logger.error(
8491
`Failed to ping service for workflow ${definitionId} at ${serviceUrl}`,
8592
);
86-
this.definitionIdCache.delete(definitionId);
93+
if (this.definitionIdCache.has(definitionId)) {
94+
this.definitionIdCache.delete(definitionId);
95+
}
8796
}
8897
}),
8998
);

0 commit comments

Comments
 (0)