2
0
mirror of https://github.com/hibiken/asynqmon.git synced 2025-10-26 16:26:12 +08:00

(ui): Fix parseDuration helper

This commit is contained in:
Ken Hibino
2021-12-02 07:39:00 -08:00
parent 7692f6bb85
commit 9964cc27b4
3 changed files with 9 additions and 5 deletions

View File

@@ -31,6 +31,12 @@ export function getMetricsAsync(endTime: number, duration: number) {
return async (dispatch: Dispatch<MetricsActionTypes>) => { return async (dispatch: Dispatch<MetricsActionTypes>) => {
dispatch({ type: GET_METRICS_BEGIN }); dispatch({ type: GET_METRICS_BEGIN });
try { try {
console.log(
"DEBUG: fetching with endtime=",
endTime,
" duration=",
duration
);
const response = await getMetrics(endTime, duration); const response = await getMetrics(endTime, duration);
dispatch({ type: GET_METRICS_SUCCESS, payload: response }); dispatch({ type: GET_METRICS_SUCCESS, payload: response });
} catch (error) { } catch (error) {

View File

@@ -51,8 +51,6 @@ const lineColors = [
]; ];
function QueueSizeMetricsChart(props: Props) { function QueueSizeMetricsChart(props: Props) {
console.log("DEBUG: QueueSizeMetricsChart props:", props);
console.log("DEBUG: chartData", toChartData(props.data));
const data = toChartData(props.data); const data = toChartData(props.data);
const keys = props.data.map((x) => x.metric.queue); const keys = props.data.map((x) => x.metric.queue);
return ( return (

View File

@@ -124,7 +124,7 @@ export function currentUnixtime(): number {
return Math.floor(Date.now() / 1000); return Math.floor(Date.now() / 1000);
} }
const durationRegex = /[1-9]([0-9]*)[s|m|h]/; const durationRegex = /([0-9]*(\.[0-9]*)?)[s|m|h]/;
// Parses the given string and returns the number of seconds if the input is valid. // Parses the given string and returns the number of seconds if the input is valid.
// Otherwise, it throws an error // Otherwise, it throws an error
// Supported time units are "s", "m", "h" // Supported time units are "s", "m", "h"
@@ -132,14 +132,14 @@ export function parseDuration(s: string): number {
if (!durationRegex.test(s)) { if (!durationRegex.test(s)) {
throw new Error("invalid duration"); throw new Error("invalid duration");
} }
const val = parseInt(s.slice(0, -1)); const val = parseFloat(s.slice(0, -1));
switch (s.slice(-1)) { switch (s.slice(-1)) {
case "s": case "s":
return val; return val;
case "m": case "m":
return val * 60; return val * 60;
case "h": case "h":
return val * 6 * 60; return val * 60 * 60;
default: default:
throw new Error("invalid duration unit"); throw new Error("invalid duration unit");
} }