fix(memory): unify host paths under real-day current
This commit is contained in:
parent
1645789bd3
commit
0c21f4e4af
18 changed files with 184 additions and 42 deletions
|
|
@ -335,12 +335,31 @@ export function appendEvent({ allowedRoot, storeRoot, event }) {
|
|||
const date = beijingDate(event.occurred_at);
|
||||
const immutablePath = eventFile(store, date, event.event_id);
|
||||
const immutableBody = stableJson({ ...event, beijing_date: date });
|
||||
const currentFile = path.join(store, "CURRENT.json");
|
||||
const previousCurrent = fs.existsSync(currentFile) ? readJson(currentFile) : null;
|
||||
if (
|
||||
previousCurrent?.updated_at &&
|
||||
new Date(event.occurred_at).valueOf() < new Date(previousCurrent.updated_at).valueOf()
|
||||
) {
|
||||
if (fs.existsSync(immutablePath) && fs.readFileSync(immutablePath, "utf8") === immutableBody) {
|
||||
return {
|
||||
outcome: "PASS",
|
||||
state: "IDEMPOTENT_OLDER_EVENT_NO_POINTER_MOVEMENT",
|
||||
date,
|
||||
event_id: event.event_id,
|
||||
current: currentFile,
|
||||
current_sha256: sha256(fs.readFileSync(currentFile, "utf8"))
|
||||
};
|
||||
}
|
||||
fail("OUT_OF_ORDER_EVENT_REQUIRES_CURRENT_CORRECTION_EVENT", {
|
||||
event_time: event.occurred_at,
|
||||
current_time: previousCurrent.updated_at
|
||||
});
|
||||
}
|
||||
if (fs.existsSync(immutablePath)) {
|
||||
if (fs.readFileSync(immutablePath, "utf8") !== immutableBody) fail("EVENT_ID_COLLISION", { event_id: event.event_id });
|
||||
} else atomicWrite(immutablePath, immutableBody);
|
||||
|
||||
const currentFile = path.join(store, "CURRENT.json");
|
||||
const previousCurrent = fs.existsSync(currentFile) ? readJson(currentFile) : null;
|
||||
closePreviousDay(store, previousCurrent, date, event.occurred_at);
|
||||
|
||||
const day = loadOrCreateDay(store, event, date, immutablePath);
|
||||
|
|
|
|||
Loading…
Reference in a new issue