- Updated FelicaHistoryPage to use dayjs for formatting scannedAt timestamps. - Refactored ResearchToolsSettings to utilize dayjs for date formatting. - Modified VoicepeakDebugLogSection to replace Date with dayjs for createdAt timestamps. - Changed settings component to use dayjs for scannedAt timestamps. - Updated ExGridSimpleView and ExGridView to use dayjs for time parsing and formatting. - Refactored ExGridSimpleViewItem and ExGridViewItem to utilize dayjs for time formatting. - Adjusted ListView and ListViewItem to use dayjs for time handling. - Updated EachData to use dayjs for train time calculations. - Refactored LED_vidion to remove redundant getServiceMinute function. - Replaced Date with dayjs in trainRecorder for exportedAt timestamps. - Updated appLifecycleCrashSentinel to use dayjs for timestamp handling. - Refactored operationInfoSchedule to use dayjs for fetchedAt timestamp. - Updated trainTimeFiltering to utilize dayjs for time comparisons. - Refactored useWebViewRemount to handle timeouts with dayjs. - Updated voicepeak and voicepeakDebugLog to use dayjs for timestamp handling. - Introduced timeUtils module for consistent time parsing and formatting using dayjs.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import dayjs from "dayjs";
|
|
const SOURCE_UPDATE_INTERVAL_MS = 5 * 60 * 1000;
|
|
const FETCH_WINDOW_START_MS = 10 * 1000;
|
|
const FETCH_WINDOW_END_MS = 50 * 1000;
|
|
const STALE_RETRY_MS = 30 * 1000;
|
|
const MIN_TIMER_DELAY_MS = 1000;
|
|
|
|
export const OPERATION_INFO_STALE_RETRY_MS = STALE_RETRY_MS;
|
|
|
|
/**
|
|
* R2の最終更新時刻を基準に、次の5分更新後10〜50秒の間へ取得を分散する。
|
|
* 更新予定時刻を過ぎてもfetchedAtが進んでいない場合は、短い間隔で再確認する。
|
|
*/
|
|
export function getNextOperationInfoFetchDelay(
|
|
fetchedAt: string,
|
|
nowMs = Date.now(),
|
|
randomValue = Math.random()
|
|
): number {
|
|
const fetchedAtMs = dayjs(fetchedAt).valueOf();
|
|
if (!Number.isFinite(fetchedAtMs)) {
|
|
return STALE_RETRY_MS;
|
|
}
|
|
|
|
const nextExpectedUpdateMs = fetchedAtMs + SOURCE_UPDATE_INTERVAL_MS;
|
|
const fetchWindowEndMs = nextExpectedUpdateMs + FETCH_WINDOW_END_MS;
|
|
const fetchWindowStartMs = Math.max(
|
|
nextExpectedUpdateMs + FETCH_WINDOW_START_MS,
|
|
nowMs + MIN_TIMER_DELAY_MS
|
|
);
|
|
|
|
if (fetchWindowStartMs >= fetchWindowEndMs) {
|
|
return STALE_RETRY_MS;
|
|
}
|
|
|
|
const clampedRandomValue = Math.min(1, Math.max(0, randomValue));
|
|
const targetMs =
|
|
fetchWindowStartMs +
|
|
(fetchWindowEndMs - fetchWindowStartMs) * clampedRandomValue;
|
|
|
|
return Math.max(MIN_TIMER_DELAY_MS, Math.round(targetMs - nowMs));
|
|
}
|