mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-28 02:47:55 +00:00
Deploy script (#52)
* No-downtime deploy script * Easier to use helper for average numbers
This commit is contained in:
@@ -2,7 +2,7 @@ import * as EventEmitter from 'events';
|
||||
import Node from './Node';
|
||||
import Feed from './Feed';
|
||||
import FeedSet from './FeedSet';
|
||||
import { Maybe, Types, FeedMessage, blockAverage } from '@dotstats/common';
|
||||
import { Maybe, Types, FeedMessage, NumStats } from '@dotstats/common';
|
||||
|
||||
const BLOCK_TIME_HISTORY = 10;
|
||||
|
||||
@@ -16,7 +16,7 @@ export default class Chain {
|
||||
public height = 0 as Types.BlockNumber;
|
||||
public blockTimestamp = 0 as Types.Timestamp;
|
||||
|
||||
private blockTimes: Array<number> = new Array(BLOCK_TIME_HISTORY).fill(0);
|
||||
private blockTimes = new NumStats<Types.Milliseconds>(BLOCK_TIME_HISTORY);
|
||||
private averageBlockTime: Maybe<Types.Milliseconds> = null;
|
||||
|
||||
constructor(label: Types.ChainLabel) {
|
||||
@@ -110,9 +110,9 @@ export default class Chain {
|
||||
}
|
||||
|
||||
private updateAverageBlockTime(height: Types.BlockNumber, now: Types.Timestamp) {
|
||||
this.blockTimes[height % BLOCK_TIME_HISTORY] = now - this.blockTimestamp;
|
||||
this.blockTimes.push((now - this.blockTimestamp) as Types.Milliseconds);
|
||||
|
||||
// We are guaranteed that count > 0
|
||||
this.averageBlockTime = blockAverage(this.blockTimes);
|
||||
this.averageBlockTime = this.blockTimes.average();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as WebSocket from 'ws';
|
||||
import * as EventEmitter from 'events';
|
||||
|
||||
import { noop, timestamp, Maybe, Types, blockAverage } from '@dotstats/common';
|
||||
import { noop, timestamp, Maybe, Types, NumStats } from '@dotstats/common';
|
||||
import { parseMessage, getBestBlock, Message, BestBlock, SystemInterval } from './message';
|
||||
import { locate, Location } from './location';
|
||||
import { getId, refreshId } from './nodeId';
|
||||
@@ -42,7 +42,7 @@ export default class Node {
|
||||
|
||||
private readonly ip: string;
|
||||
private readonly socket: WebSocket;
|
||||
private blockTimes: Array<number> = new Array(BLOCK_TIME_HISTORY);
|
||||
private blockTimes = new NumStats<Types.Milliseconds>(BLOCK_TIME_HISTORY);
|
||||
private lastBlockAt: Maybe<Date> = null;
|
||||
private pingStart = 0 as Types.Timestamp;
|
||||
private throttle = false;
|
||||
@@ -189,7 +189,7 @@ export default class Node {
|
||||
}
|
||||
|
||||
public get average(): Types.Milliseconds {
|
||||
return blockAverage(this.blockTimes);
|
||||
return this.blockTimes.average();
|
||||
}
|
||||
|
||||
public get localBlockAt(): Types.Milliseconds {
|
||||
@@ -265,7 +265,7 @@ export default class Node {
|
||||
this.height = height;
|
||||
this.blockTimestamp = timestamp();
|
||||
this.lastBlockAt = time;
|
||||
this.blockTimes[height % BLOCK_TIME_HISTORY] = blockTime;
|
||||
this.blockTimes.push(blockTime);
|
||||
this.blockTime = blockTime;
|
||||
|
||||
if (blockTime > 100) {
|
||||
|
||||
Reference in New Issue
Block a user