mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 04:32:42 +00:00
One-shot prettier pass so the new format:check gate starts from a clean baseline. Formatting only — no behaviour change. Generator-owned and vendored artifacts stay untouched via .prettierignore.
35 lines
963 B
TypeScript
35 lines
963 B
TypeScript
import { WideEventBuilder } from "./event-builder";
|
|
import { eventStorage } from "./context";
|
|
import { emitIfSampled } from "./transports";
|
|
|
|
/**
|
|
* Hintergrundaufgabe mit Wide-Event-Logging ausfuehren.
|
|
*
|
|
* Beispiel:
|
|
* await withBackgroundEvent("scheduler.tick", async (evt) => {
|
|
* const results = await sendDailyReminders(currentTime);
|
|
* evt.setBackground({ task_name: "scheduler.tick", result: results });
|
|
* });
|
|
*/
|
|
export async function withBackgroundEvent<T>(
|
|
taskName: string,
|
|
fn: (evt: WideEventBuilder) => Promise<T>,
|
|
): Promise<T> {
|
|
const evt = new WideEventBuilder("background");
|
|
evt.setBackground({ task_name: taskName });
|
|
|
|
return eventStorage.run(evt, async () => {
|
|
try {
|
|
const result = await fn(evt);
|
|
evt.finish();
|
|
emitIfSampled(evt.toJSON());
|
|
return result;
|
|
} catch (error) {
|
|
evt.setError(error);
|
|
evt.finish();
|
|
emitIfSampled(evt.toJSON());
|
|
throw error;
|
|
}
|
|
});
|
|
}
|