Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Apr 13, 2022
1 parent 9aaf203 commit bcdd762
Show file tree
Hide file tree
Showing 9 changed files with 846 additions and 694 deletions.
6 changes: 3 additions & 3 deletions app/src/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export function getAdminRouter(redis: Redis): Router {
async function getDashboardValues(redis: Redis): Promise<unknown> {
const redisOut = await redis.pipeline().get(Keys.dsLastRequestSec).get(Keys.trackNum).exec();

const cacheTimeSec = Number(redisOut[0][1] ?? 0);
const trackOffset = Number(redisOut[1][1] ?? NUM_TRACKS_OFFSET) - 100;
const cacheTimeSec = Number(redisOut![0][1] ?? 0);
const trackOffset = Number(redisOut![1][1] ?? NUM_TRACKS_OFFSET) - 100;

const nowSec = Math.round(Date.now() / 1000);

Expand Down Expand Up @@ -194,7 +194,7 @@ async function getDashboardValues(redis: Redis): Promise<unknown> {
const values: { [key: string]: string | string[] } = {};

Object.keys(typeByKey).forEach((key, i) => {
values[key] = result[i][1];
values[key] = result![i][1] as string | string[];
});

return values;
Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/live-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getTrackerRouter(redis: Redis): Router {
case SecretKeys.FLYME_TOKEN:
const groupProto = await redis.getBuffer(Keys.fetcherExportFlymeProto);
if (req.header('accept') == 'application/json') {
const track = LiveDifferentialTrackGroup.fromBinary(groupProto);
const track = LiveDifferentialTrackGroup.fromBinary(groupProto!);
res.json(LiveDifferentialTrackGroup.toJson(track));
} else {
res.set('Content-Type', 'application/x-protobuf');
Expand Down
10 changes: 5 additions & 5 deletions common/src/redis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IORedis from 'ioredis';
import Redis, { ChainableCommander } from 'ioredis';

import { SecretKeys } from './keys';

Expand Down Expand Up @@ -109,12 +109,12 @@ export const enum Keys {
}

// lazily created client.
let redis: IORedis.Redis | undefined;
let redis: Redis | undefined;

export function getRedisClient(): IORedis.Redis {
export function getRedisClient(): Redis {
if (!redis) {
const keyPrefix = process.env.NODE_ENV == 'development' ? 'dev:' : undefined;
redis = new IORedis(SecretKeys.REDIS_URL, { keyPrefix });
redis = new Redis(SecretKeys.REDIS_URL, { keyPrefix });
}
return redis;
}
Expand All @@ -127,7 +127,7 @@ export function getRedisClient(): IORedis.Redis {
// - each value is limited to maxLength chars,
// - most recent list elements should be last (tail is dropped first).
export function pushListCap(
pipeline: IORedis.Pipeline,
pipeline: ChainableCommander,
key: string,
list: Array<string | number>,
capacity: number,
Expand Down
4 changes: 2 additions & 2 deletions fetcher/src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TrackerIds,
} from 'flyxc/common/src/live-track';
import { getRedisClient, Keys } from 'flyxc/common/src/redis';
import { Pipeline } from 'ioredis';
import { ChainableCommander } from 'ioredis';
import process from 'process';

import { patchLastFixAGL as patchLastFixElevation } from './elevation/elevation';
Expand Down Expand Up @@ -156,7 +156,7 @@ async function tick(state: FetcherState) {
}

// Update every tick.
async function updateTrackers(pipeline: Pipeline, state: FetcherState) {
async function updateTrackers(pipeline: ChainableCommander, state: FetcherState) {
try {
const fetchers = [
new InreachFetcher(state),
Expand Down
18 changes: 9 additions & 9 deletions fetcher/src/redis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FetcherState, Tracker } from 'flyxc/common/protos/fetcher-state';
import { trackerPropNames } from 'flyxc/common/src/live-track';
import { Keys, pushListCap } from 'flyxc/common/src/redis';
import { Pipeline, Redis } from 'ioredis';
import { ChainableCommander, Redis } from 'ioredis';
import nos from 'node-os-utils';
import zlib from 'zlib';

Expand All @@ -12,7 +12,7 @@ import { syncFromDatastore, SyncStatus } from './state/sync';
import { TrackerUpdates } from './trackers/tracker';

// Logs for syncs.
export function addSyncLogs(pipeline: Pipeline, status: SyncStatus, timeSec: number) {
export function addSyncLogs(pipeline: ChainableCommander, status: SyncStatus, timeSec: number) {
const type = status.full ? 'full' : 'inc';

if (status.errors.length) {
Expand All @@ -23,12 +23,12 @@ export function addSyncLogs(pipeline: Pipeline, status: SyncStatus, timeSec: num
}

// Logs for export to datastore.
export function addExportLogs(pipeline: Pipeline, success: boolean, timeSec: number) {
export function addExportLogs(pipeline: ChainableCommander, success: boolean, timeSec: number) {
pushListCap(pipeline, Keys.stateExportStatus, [`[${timeSec}] ${success ? 'ok' : 'ko'}`], 5);
}

// Logs the elevation updates.
export function addElevationLogs(pipeline: Pipeline, updates: ElevationUpdates, timeSec: number): void {
export function addElevationLogs(pipeline: ChainableCommander, updates: ElevationUpdates, timeSec: number): void {
pushListCap(
pipeline,
Keys.elevationErrors,
Expand All @@ -40,7 +40,7 @@ export function addElevationLogs(pipeline: Pipeline, updates: ElevationUpdates,
}

// Logs updates for a tracker type.
export function addTrackerLogs(pipeline: Pipeline, updates: TrackerUpdates, state: FetcherState): void {
export function addTrackerLogs(pipeline: ChainableCommander, updates: TrackerUpdates, state: FetcherState): void {
const name = trackerPropNames[updates.trackerId];
const time = updates.startFetchSec;

Expand Down Expand Up @@ -92,7 +92,7 @@ let cpuUsage = 0;
let cpuUsagePromise: Promise<number> | null = null;

// Logs host info.
export async function addHostInfo(pipeline: Pipeline): Promise<void> {
export async function addHostInfo(pipeline: ChainableCommander): Promise<void> {
// CPU usage over 5min.
if (cpuUsagePromise == null) {
cpuUsagePromise = nos.cpu
Expand All @@ -111,7 +111,7 @@ export async function addHostInfo(pipeline: Pipeline): Promise<void> {
}

// Logs state variables.
export function addStateLogs(pipeline: Pipeline, state: FetcherState): void {
export function addStateLogs(pipeline: ChainableCommander, state: FetcherState): void {
pipeline
.set(Keys.fetcherMemoryHeapMb, state.memHeapMb)
.set(Keys.fetcherMemoryRssMb, state.memRssMb)
Expand Down Expand Up @@ -152,13 +152,13 @@ export function addStateLogs(pipeline: Pipeline, state: FetcherState): void {
// Handle the commands received via REDIS.
export async function HandleCommand(redis: Redis, state: FetcherState): Promise<void> {
try {
const [[, cmdCapture], [, cmdExport], [, cmdSyncCount], [, cmdSyncFull]] = await redis
const [[, cmdCapture], [, cmdExport], [, cmdSyncCount], [, cmdSyncFull]] = (await redis
.pipeline()
.get(Keys.fetcherCmdCaptureState)
.get(Keys.fetcherCmdExportFile)
.get(Keys.fetcherCmdSyncIncCount)
.get(Keys.fetcherCmdSyncFull)
.exec();
.exec()) as [error: Error | null, result: unknown][];

if (cmdCapture != null) {
const snapshot = Buffer.from(FetcherState.toBinary(state));
Expand Down
Loading

0 comments on commit bcdd762

Please sign in to comment.