Skip to content

Commit 3fd7ef1

Browse files
committed
Send the rest of the information over in the handshake request.
1 parent 8ae72c2 commit 3fd7ef1

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Source/sdk/Internal/RuntimeConnector.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import { Logger } from 'winston';
55
import { from, Notification, Observable, timer } from 'rxjs';
6-
import { concatMap, delayWhen, dematerialize, map } from 'rxjs/operators';
6+
import { concatMap, delayWhen, dematerialize, map, timestamp } from 'rxjs/operators';
77
import { status as GrpcStatus } from '@grpc/grpc-js';
8+
import { Duration } from 'google-protobuf/google/protobuf/duration_pb';
89

910
import { Claims, CorrelationId, Environment, ExecutionContext, MicroserviceId, TenantId, Version } from '@dolittle/sdk.execution';
1011
import { Failures, Guids, Versions } from '@dolittle/sdk.protobuf';
@@ -73,7 +74,6 @@ export class RuntimeConnector extends ICanConnectToARuntime {
7374
if (response.hasFailure()) {
7475
const failure = Failures.toSDK(response.getFailure()!);
7576
throw new RuntimeHandshakeFailed(failure.reason);
76-
// TODO: Handle incompatible versions failure ID
7777
}
7878

7979
return this.createExecutionContextFrom(response);
@@ -119,12 +119,16 @@ export class RuntimeConnector extends ICanConnectToARuntime {
119119
private createHandshakeRequest(attempt: number, millisecondsSinceStart: number): HandshakeRequest {
120120
const handshakeRequest = new HandshakeRequest();
121121

122-
handshakeRequest.setSdk('JS.SDK');
122+
handshakeRequest.setSdkidentifier('JavaScript');
123123
handshakeRequest.setHeadversion(Versions.toProtobuf(this._headVersion));
124124
handshakeRequest.setSdkversion(Versions.toProtobuf(VersionInfo.currentVersion));
125125
handshakeRequest.setContractsversion(ContractsVersionInfo.getCurrentVersion());
126126

127-
// TODO: Add attempt and time since start to request
127+
const timeSpent = new Duration();
128+
timeSpent.setSeconds(Math.trunc(millisecondsSinceStart/1e3));
129+
timeSpent.setNanos((millisecondsSinceStart % 1e3) * 1e6);
130+
handshakeRequest.setAttempt(attempt);
131+
handshakeRequest.setTimespent(timeSpent);
128132

129133
return handshakeRequest;
130134
}
@@ -137,7 +141,7 @@ export class RuntimeConnector extends ICanConnectToARuntime {
137141
this._logger.debug(`Received initial booting configuration from Runtime running version ${runtimeVersion} using Contracts version ${contractsVersion}`);
138142

139143
const microserviceId = MicroserviceId.from(Guids.toSDK(response.getMicroserviceid()));
140-
const environment = Environment.from(response.getEnvironment());
144+
const environment = Environment.from(response.getEnvironmentname());
141145

142146
return new ExecutionContext(
143147
microserviceId,
@@ -152,6 +156,6 @@ export class RuntimeConnector extends ICanConnectToARuntime {
152156
if (!response.hasRuntimeversion()) throw new RuntimeHandshakeMissingInformation('Runtime version');
153157
if (!response.hasContractsversion()) throw new RuntimeHandshakeMissingInformation('Contracts version');
154158
if (!response.hasMicroserviceid()) throw new RuntimeHandshakeMissingInformation('microservice ID');
155-
if (response.getEnvironment() === '') throw new RuntimeHandshakeMissingInformation('environment');
159+
if (response.getEnvironmentname() === '') throw new RuntimeHandshakeMissingInformation('environment');
156160
}
157161
}

0 commit comments

Comments
 (0)