Skip to content

Commit

Permalink
fix(orchestrator): return instance ID also on failed execute workflow…
Browse files Browse the repository at this point in the history
… API call (backport 1.3) (#2525)

fix(orchestrator): Return instance ID also on failed execute workflow API call
  • Loading branch information
batzionb authored Nov 12, 2024
1 parent 358dbfd commit 8af20a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .changeset/great-keys-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('SonataFlowService', () => {
);
expect(result).toEqual({ id: definitionId, status: 'completed' });
expect(loggerMock.debug).toHaveBeenCalledWith(
`Execute workflow result: {"id":"${definitionId}","status":"completed"}`,
'Execute workflow successful. Response: {"id":"workflow-123","status":"completed"}',
);
// Verify that all other logger methods were not called
expect(loggerMock.debug).toHaveBeenCalledTimes(1);
Expand Down
26 changes: 20 additions & 6 deletions plugins/orchestrator-backend/src/service/SonataFlowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,28 @@ export class SonataFlowService {
headers: { 'content-type': 'application/json' },
});

if (response.ok) {
const json = await response.json();
this.logger.debug(`Execute workflow result: ${JSON.stringify(json)}`);
const json = await response.json();
if (json.id) {
this.logger.debug(
`Execute workflow successful. Response: ${JSON.stringify(json)}`,
);
return json;
} else if (!response.ok) {
const errorMessage = await this.createPrefixFetchErrorMessage(
urlToFetch,
response,
'POST',
);
this.logger.error(
`Execute workflow failed. Response: ${JSON.stringify(json)}`,
);
throw new Error(errorMessage);
} else {
this.logger.error(
`Execute workflow did not return a workflow instance ID. Response: ${JSON.stringify(json)}`,
);
throw new Error('Execute workflow did not return a workflow instance ID');
}
throw new Error(
`${await this.createPrefixFetchErrorMessage(urlToFetch, response, 'POST')}`,
);
}

public async fetchWorkflowOverview(
Expand Down
21 changes: 15 additions & 6 deletions plugins/orchestrator-backend/src/service/WorkflowCacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,26 @@ export class WorkflowCacheService {
});
await Promise.all(
Object.entries(idUrlMap).map(async ([definitionId, serviceUrl]) => {
const isServiceUp = await this.sonataFlowService.pingWorkflowService({
definitionId,
serviceUrl,
});
let isServiceUp = false;
try {
isServiceUp = await this.sonataFlowService.pingWorkflowService({
definitionId,
serviceUrl,
});
} catch (err) {
this.logger.error(
`Ping workflow ${definitionId} service threw error: ${err}`,
);
}
if (isServiceUp) {
this.definitionIdCache.add(definitionId);
} else if (this.definitionIdCache.has(definitionId)) {
} else {
this.logger.error(
`Failed to ping service for workflow ${definitionId} at ${serviceUrl}`,
);
this.definitionIdCache.delete(definitionId);
if (this.definitionIdCache.has(definitionId)) {
this.definitionIdCache.delete(definitionId);
}
}
}),
);
Expand Down

0 comments on commit 8af20a1

Please sign in to comment.