diff --git a/lib/ExecutionLog.js b/lib/ExecutionLog.js index 618127b..704136b 100644 --- a/lib/ExecutionLog.js +++ b/lib/ExecutionLog.js @@ -482,6 +482,17 @@ export default class ExecutionLog { timestamp }; + // Prefer server-side process instance startDate over the client-side timestamp + if (this._startInstanceResponse && result.processInstanceResponse?.success) { + const serverStartDate = toTimestamp( + result.processInstanceResponse.response?.items?.[0]?.startDate + ); + + if (serverStartDate) { + this._startInstanceResponse.timestamp = serverStartDate; + } + } + this._updateEntries(); } diff --git a/test/ExecutionLog.spec.js b/test/ExecutionLog.spec.js index e738431..4a60a51 100644 --- a/test/ExecutionLog.spec.js +++ b/test/ExecutionLog.spec.js @@ -12,6 +12,7 @@ import { createGetProcessInstanceElementInstancesResponse, createGetProcessInstanceJobsResponse, createGetProcessInstanceMessageSubscriptionsResponse, + createGetProcessInstanceResponse, createGetProcessInstanceUserTasksResponse, createGetProcessInstanceVariablesResponse, createElementInstanceDetails, @@ -20,6 +21,7 @@ import { createMessageSubscriptionDetails, createMockDate, createMockTimestamp, + createProcessInstanceDetails, createUserTaskDetails, ONE_SECOND_MS, DEFAULT_PROCESS_INSTANCE_KEY, @@ -796,13 +798,19 @@ describe('ExecutionLog', function() { // when executionLog.setDeployResponse(createDeployResponse(), createMockTimestamp()); - executionLog.setStartInstanceResponse(createStartInstanceResponse(), createMockTimestamp(ONE_SECOND_MS)); + executionLog.setStartInstanceResponse(createStartInstanceResponse(), createMockTimestamp(ONE_SECOND_MS * 3)); executionLog.setPolledResult(createPolledResult({ jobsResponse: createGetProcessInstanceJobsResponse({ response: { items: [ job ] } }), elementInstancesResponse: createGetProcessInstanceElementInstancesResponse({ response: { items: [ elementInstance ] } + }), + processInstanceResponse: createGetProcessInstanceResponse({ + response: { + items: [ createProcessInstanceDetails({ startDate: createMockDate(ONE_SECOND_MS) }) ], + page: { totalItems: 1 } + } }) }), createMockTimestamp(ONE_SECOND_MS * 6)); @@ -814,6 +822,18 @@ describe('ExecutionLog', function() { for (let i = 1; i < timestamps.length; i++) { expect(timestamps[i]).to.be.at.least(timestamps[i - 1]); } + + // Verify instance-started comes before element-instance entries + const types = entries.map(e => e.status || `${e.type}:${e.data?.state}`); + + expect(types).to.deep.equal([ + 'deployed', + 'instance-started', + 'element-instance:ACTIVE', + 'job:CREATED', + 'job:COMPLETED', + 'element-instance:COMPLETED' + ]); }); });