perf(server): daemonize startup heartbeat analytics
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
c296cee137
commit
03d24d6110
2 files changed
+39
-6
No files matched your search
@@ -1,8 +1,13 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Deferred, Effect, Fiber, Ref } from "effect";
|
||||
import { TestClock } from "effect/testing";
|
||||
import { Deferred, Effect, Fiber, Option, Ref } from "effect";
|
||||
|
||||
import { makeCommandGate, ServerRuntimeStartupError } from "./serverRuntimeStartup.ts";
|
||||
import { AnalyticsService } from "./telemetry/Services/AnalyticsService.ts";
|
||||
import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import {
|
||||
launchStartupHeartbeat,
|
||||
makeCommandGate,
|
||||
ServerRuntimeStartupError,
|
||||
} from "./serverRuntimeStartup.ts";
|
||||
|
||||
it.effect("enqueueCommand waits for readiness and then drains queued work", () =>
|
||||
Effect.scoped(
|
||||
@@ -14,7 +19,7 @@ it.effect("enqueueCommand waits for readiness and then drains queued work", () =
|
||||
.enqueueCommand(Ref.updateAndGet(executionCount, (count) => count + 1))
|
||||
.pipe(Effect.forkScoped);
|
||||
|
||||
yield* TestClock.adjust("50 millis");
|
||||
yield* Effect.yieldNow;
|
||||
assert.equal(yield* Ref.get(executionCount), 0);
|
||||
|
||||
yield* commandGate.signalCommandReady;
|
||||
@@ -47,3 +52,25 @@ it.effect("enqueueCommand fails queued work when readiness fails", () =>
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("launchStartupHeartbeat does not block the caller while counts are loading", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const releaseCounts = yield* Deferred.make<void, never>();
|
||||
|
||||
yield* launchStartupHeartbeat.pipe(
|
||||
Effect.provideService(ProjectionSnapshotQuery, {
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getCounts: () => Deferred.await(releaseCounts),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
|
||||
getFirstActiveThreadIdByProjectId: () => Effect.succeed(Option.none()),
|
||||
getThreadCheckpointContext: () => Effect.succeed(Option.none()),
|
||||
}),
|
||||
Effect.provideService(AnalyticsService, {
|
||||
record: () => Effect.void,
|
||||
flush: Effect.void,
|
||||
}),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
@@ -117,7 +117,7 @@ export const makeCommandGate = Effect.gen(function* () {
|
||||
} satisfies CommandGate;
|
||||
});
|
||||
|
||||
const recordStartupHeartbeat = Effect.gen(function* () {
|
||||
export const recordStartupHeartbeat = Effect.gen(function* () {
|
||||
const analytics = yield* AnalyticsService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
|
||||
@@ -140,6 +140,12 @@ const recordStartupHeartbeat = Effect.gen(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
export const launchStartupHeartbeat = recordStartupHeartbeat.pipe(
|
||||
Effect.ignoreCause({ log: true }),
|
||||
Effect.forkScoped,
|
||||
Effect.asVoid,
|
||||
);
|
||||
|
||||
const autoBootstrapWelcome = Effect.gen(function* () {
|
||||
const serverConfig = yield* ServerConfig;
|
||||
const projectionReadModelQuery = yield* ProjectionSnapshotQuery;
|
||||
@@ -322,7 +328,7 @@ const makeServerRuntimeStartup = Effect.gen(function* () {
|
||||
});
|
||||
|
||||
yield* Effect.logDebug("startup phase: recording startup heartbeat");
|
||||
yield* recordStartupHeartbeat;
|
||||
yield* launchStartupHeartbeat;
|
||||
yield* Effect.logDebug("startup phase: browser open check");
|
||||
yield* maybeOpenBrowser;
|
||||
yield* Effect.logDebug("startup phase: complete");
|
||||
|
||||
Reference in new issue
Block a user