Fix: Use seconds for unix timestamps to not compare seconds and milliseconds.
This commit is contained in:
parent
d06c732cfe
commit
3a253ba72e
|
@ -16,7 +16,7 @@ import {normalizeMac} from "../utils/strings";
|
|||
import {monitoringDisableUrl} from "../utils/urlBuilder";
|
||||
import CONSTRAINTS from "../validation/constraints";
|
||||
import {forConstraint} from "../validation/validator";
|
||||
import {MAC, MailType, Node, NodeId, NodeState, NodeStateData, UnixTimestamp} from "../types";
|
||||
import {MAC, MailType, Node, NodeId, NodeState, NodeStateData, UnixTimestampSeconds} from "../types";
|
||||
|
||||
const MONITORING_STATE_MACS_CHUNK_SIZE = 100;
|
||||
const NEVER_ONLINE_NODES_DELETION_CHUNK_SIZE = 20;
|
||||
|
@ -688,7 +688,7 @@ export async function deleteOfflineNodes(): Promise<void> {
|
|||
await deleteNodesOfflineSinceBefore(deleteBefore);
|
||||
}
|
||||
|
||||
async function deleteNeverOnlineNodesBefore(deleteBefore: UnixTimestamp): Promise<void> {
|
||||
async function deleteNeverOnlineNodesBefore(deleteBefore: UnixTimestampSeconds): Promise<void> {
|
||||
Logger
|
||||
.tag('nodes', 'delete-never-online')
|
||||
.info(
|
||||
|
@ -765,7 +765,7 @@ async function deleteNeverOnlineNodesBefore(deleteBefore: UnixTimestamp): Promis
|
|||
}
|
||||
}
|
||||
|
||||
async function deleteNodesOfflineSinceBefore(deleteBefore: UnixTimestamp): Promise<void> {
|
||||
async function deleteNodesOfflineSinceBefore(deleteBefore: UnixTimestampSeconds): Promise<void> {
|
||||
const rows = await db.all(
|
||||
'SELECT * FROM node_state WHERE state = ? AND last_seen < ?',
|
||||
[
|
||||
|
|
|
@ -10,7 +10,7 @@ import Logger from "../logger";
|
|||
import * as MailService from "../services/mailService";
|
||||
import {normalizeString} from "../utils/strings";
|
||||
import {monitoringConfirmUrl, monitoringDisableUrl} from "../utils/urlBuilder";
|
||||
import {FastdKey, MonitoringState, MonitoringToken, Node, NodeSecrets, NodeStatistics, UnixTimestamp, Token} from "../types";
|
||||
import {FastdKey, MonitoringState, MonitoringToken, Node, NodeSecrets, NodeStatistics, UnixTimestampSeconds, Token} from "../types";
|
||||
import util from "util";
|
||||
|
||||
const pglob = util.promisify(glob);
|
||||
|
@ -235,7 +235,7 @@ async function deleteNodeFile(token: Token): Promise<void> {
|
|||
async function parseNodeFile(file: string): Promise<{node: Node, nodeSecrets: NodeSecrets}> {
|
||||
const contents = await fs.readFile(file);
|
||||
const stats = await fs.lstat(file);
|
||||
const modifiedAt = stats.mtimeMs;
|
||||
const modifiedAt = Math.floor(stats.mtimeMs / 1000);
|
||||
|
||||
const lines = contents.toString();
|
||||
|
||||
|
@ -491,7 +491,7 @@ export async function fixNodeFilenames(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function findNodesModifiedBefore(timestamp: UnixTimestamp): Promise<Node[]> {
|
||||
export async function findNodesModifiedBefore(timestamp: UnixTimestampSeconds): Promise<Node[]> {
|
||||
const nodes = await getAllNodes();
|
||||
return _.filter(nodes, node => node.modifiedAt < timestamp);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ export type Token = string;
|
|||
export type FastdKey = string;
|
||||
export type MAC = string;
|
||||
|
||||
export type UnixTimestamp = number;
|
||||
export type UnixTimestampSeconds = number;
|
||||
export type UnixTimestampMilliseconds = number;
|
||||
|
||||
export type MonitoringToken = string;
|
||||
export enum MonitoringState {
|
||||
|
@ -39,7 +40,7 @@ export type Node = {
|
|||
monitoring: boolean;
|
||||
monitoringConfirmed: boolean;
|
||||
monitoringState: MonitoringState;
|
||||
modifiedAt: UnixTimestamp;
|
||||
modifiedAt: UnixTimestampSeconds;
|
||||
};
|
||||
|
||||
// TODO: Complete interface / class declaration.
|
||||
|
|
Loading…
Reference in a new issue