Skip to content

Commit

Permalink
fix: uintroduce call to update last_seen on client-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarconr committed Dec 10, 2021
1 parent 573385a commit 08bff63
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/lib/db/client-instance-store.ts
Expand Up @@ -77,6 +77,19 @@ export default class ClientInstanceStore implements IClientInstanceStore {
}
}

async setLastSeen({
appName,
instanceId,
environment,
clientIp,
}: INewClientInstance): Promise<void> {
await this.db(TABLE)
.update({ last_seen: new Date(), client_ip: clientIp })
.where({ app_name: appName, instance_id: instanceId, environment })
.onConflict(['app_name', 'instance_id', 'environment'])
.ignore();
}

async bulkUpsert(instances: INewClientInstance[]): Promise<void> {
const rows = instances.map(mapToDb);
await this.db(TABLE)
Expand Down
5 changes: 3 additions & 2 deletions src/lib/services/client-metrics/instance-service.ts
Expand Up @@ -94,10 +94,11 @@ export default class ClientInstanceService {
clientIp: string,
): Promise<void> {
const value = await clientMetricsSchema.validateAsync(data);
await this.clientInstanceStore.insert({
await this.clientInstanceStore.setLastSeen({
appName: value.appName,
instanceId: value.instanceId,
clientIp,
environment: value.environment,
clientIp: clientIp,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/types/stores/client-instance-store.ts
Expand Up @@ -18,6 +18,7 @@ export interface IClientInstanceStore
Pick<INewClientInstance, 'appName' | 'instanceId'>
> {
bulkUpsert(instances: INewClientInstance[]): Promise<void>;
setLastSeen(INewClientInstance): Promise<void>;
insert(details: INewClientInstance): Promise<void>;
getByAppName(appName: string): Promise<IClientInstance[]>;
getDistinctApplications(): Promise<string[]>;
Expand Down
4 changes: 4 additions & 0 deletions src/test/fixtures/fake-client-instance-store.ts
Expand Up @@ -27,6 +27,10 @@ export default class FakeClientInstanceStore implements IClientInstanceStore {
);
}

setLastSeen(): Promise<void> {
return;
}

async deleteAll(): Promise<void> {
this.instances = [];
}
Expand Down

1 comment on commit 08bff63

@vercel
Copy link

@vercel vercel bot commented on 08bff63 Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.