Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

remove outbox from interfaces

Thiago Araujo da Silvaf5d471ff08a3
diff --git a/backend/src/services/alert/alert-event-consumer.ts b/backend/src/services/alert/alert-event-consumer.ts
index 44bc27bf6a..ca97c93ed7 100644
--- a/backend/src/services/alert/alert-event-consumer.ts
+++ b/backend/src/services/alert/alert-event-consumer.ts
@@ -2,11 +2,7 @@ import { z } from "zod";
import { TEventOutbox } from "@app/db/schemas";
import { AlertDispatchOutcome, recordAlertDispatchOutcomeMetric } from "@app/lib/telemetry/metrics";
-import {
- EventOutboxStatus,
- IEventOutboxConsumer,
- TOutboxEventResult
-} from "@app/services/event-outbox/event-outbox-types";
+import { EventOutboxStatus, IEventConsumer, TEventConsumerResult } from "@app/services/event-outbox/event-outbox-types";
import { TAlertDALFactory } from "./alert-dal";
import { TAlertEngine } from "./alert-engine";
@@ -37,7 +33,7 @@ export const alertEventConsumerFactory = ({
alertDAL,
alertEngine,
alertProviderRegistry
-}: TAlertEventConsumerDep): IEventOutboxConsumer<z.infer<typeof AlertEventPayloadSchema>> => {
+}: TAlertEventConsumerDep): IEventConsumer<z.infer<typeof AlertEventPayloadSchema>> => {
const subscribesTo = (eventType: string): boolean => alertProviderRegistry.eventTriggeredKeys().has(eventType);
// subscribesTo only sees the event type, so a valid event key on the wrong resourceType gets past it.
@@ -49,7 +45,7 @@ export const alertEventConsumerFactory = ({
?.events.some((declared) => declared.key === event.eventType && declared.triggerType === AlertTriggerType.Event)
);
- const $handleEvent = async (event: TEventOutbox, findAlerts: TAlertLookup): Promise<TOutboxEventResult> => {
+ const $handleEvent = async (event: TEventOutbox, findAlerts: TAlertLookup): Promise<TEventConsumerResult> => {
const id = String(event.id);
if (!$isDeclaredEvent(event)) {
@@ -116,7 +112,7 @@ export const alertEventConsumerFactory = ({
return { ...outcome, status: EventOutboxStatus.Delivered };
};
- const handle = async (events: TEventOutbox[]): Promise<TOutboxEventResult[]> => {
+ const handle = async (events: TEventOutbox[]): Promise<TEventConsumerResult[]> => {
const alertsByScope = new Map<string, ReturnType<TAlertLookup>>();
const findAlerts: TAlertLookup = (filter) => {
const key = `${filter.orgId}|${filter.projectId ?? ""}|${filter.eventType}`;
@@ -128,7 +124,7 @@ export const alertEventConsumerFactory = ({
return lookup;
};
- const results: TOutboxEventResult[] = [];
+ const results: TEventConsumerResult[] = [];
for (const event of events) {
try {
diff --git a/backend/src/services/event-outbox/event-outbox-registry.ts b/backend/src/services/event-outbox/event-outbox-registry.ts
index c6cda210a5..60cca823b7 100644
--- a/backend/src/services/event-outbox/event-outbox-registry.ts
+++ b/backend/src/services/event-outbox/event-outbox-registry.ts
@@ -1,22 +1,22 @@
-import { IEventOutboxConsumer } from "./event-outbox-types";
+import { IEventConsumer } from "./event-outbox-types";
export type TEventOutboxRegistry = ReturnType<typeof eventOutboxRegistryFactory>;
export const eventOutboxRegistryFactory = () => {
- const consumers = new Map<string, IEventOutboxConsumer>();
+ const consumers = new Map<string, IEventConsumer>();
- const register = (consumer: IEventOutboxConsumer) => {
+ const register = (consumer: IEventConsumer) => {
if (consumers.has(consumer.name)) {
throw new Error(`Event outbox consumer already registered under the name '${consumer.name}'`);
}
consumers.set(consumer.name, consumer);
};
- const get = (name: string): IEventOutboxConsumer | undefined => consumers.get(name);
+ const get = (name: string): IEventConsumer | undefined => consumers.get(name);
const names = (): string[] => [...consumers.keys()];
- const subscribersOf = (eventType: string): IEventOutboxConsumer[] =>
+ const subscribersOf = (eventType: string): IEventConsumer[] =>
[...consumers.values()].filter((consumer) => consumer.subscribesTo(eventType));
return { register, get, names, subscribersOf };
diff --git a/backend/src/services/event-outbox/event-outbox-service.test.ts b/backend/src/services/event-outbox/event-outbox-service.test.ts
index 6bf8cdc5b9..d53d80a0d7 100644
--- a/backend/src/services/event-outbox/event-outbox-service.test.ts
+++ b/backend/src/services/event-outbox/event-outbox-service.test.ts
@@ -6,7 +6,7 @@ import { eventOutboxRegistryFactory } from "./event-outbox-registry";
import { eventOutboxServiceFactory } from "./event-outbox-service";
import {
EventOutboxStatus,
- IEventOutboxConsumer,
+ IEventConsumer,
MAX_OUTBOX_ATTEMPTS,
MAX_OUTBOX_PAYLOAD_BYTES,
TOutboxEvent
@@ -37,20 +37,20 @@ const makeEvent = (overrides?: Partial<TOutboxEvent>): TOutboxEvent => ({
...overrides
});
-const makeConsumer = (overrides?: Partial<IEventOutboxConsumer>): IEventOutboxConsumer =>
+const makeConsumer = (overrides?: Partial<IEventConsumer>): IEventConsumer =>
({
name: "alert",
payloadSchema: z.object({ targetIds: z.array(z.string()).min(1) }),
subscribesTo: (eventType: string) => eventType === "approval.workflow.request_opened",
handle: async () => [],
...overrides
- }) as IEventOutboxConsumer;
+ }) as IEventConsumer;
// `tx` is a sentinel: emit has to thread the caller's transaction through untouched, since a call
// that silently opens its own connection is how the pool deadlocks.
const TX = { sentinel: true } as never;
-const buildService = (consumers: IEventOutboxConsumer[]) => {
+const buildService = (consumers: IEventConsumer[]) => {
const registry = eventOutboxRegistryFactory();
consumers.forEach((consumer) => registry.register(consumer));
@@ -170,7 +170,7 @@ describe("event outbox drain", () => {
const buildDrain = (opts: {
batches: TEventOutbox[][];
- handle: IEventOutboxConsumer["handle"];
+ handle: IEventConsumer["handle"];
consumerName?: string;
settled?: (input: { delivered: { ids: string[] }[] }) => number;
}) => {
diff --git a/backend/src/services/event-outbox/event-outbox-service.ts b/backend/src/services/event-outbox/event-outbox-service.ts
index 1b97079b5f..3130cc58eb 100644
--- a/backend/src/services/event-outbox/event-outbox-service.ts
+++ b/backend/src/services/event-outbox/event-outbox-service.ts
@@ -12,15 +12,15 @@ import {
DELIVERED_RETENTION_MS,
EventOutboxStatus,
FAILED_RETENTION_MS,
- IEventOutboxConsumer,
+ IEventConsumer,
MAX_BATCHES_PER_FLUSH,
MAX_OUTBOX_ATTEMPTS,
MAX_OUTBOX_PAYLOAD_BYTES,
OUTBOX_CLAIM_BATCH_SIZE,
OutboxEventSchema,
STALE_CLAIM_THRESHOLD_MS,
+ TEventConsumerResult,
TOutboxEvent,
- TOutboxEventResult,
TOutboxFlushKey
} from "./event-outbox-types";
@@ -145,7 +145,7 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistry
const $applyResults = async (
rows: TEventOutbox[],
lockToken: string,
- results: TOutboxEventResult[]
+ results: TEventConsumerResult[]
): Promise<void> => {
const byId = new Map(results.map((result) => [result.id, result]));
const now = Date.now();
@@ -170,7 +170,7 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistry
};
const attempts = row.attempts + 1;
- let finalStatus: TOutboxEventResult["status"];
+ let finalStatus: TEventConsumerResult["status"];
if (result.status === EventOutboxStatus.Delivered) {
finalStatus = EventOutboxStatus.Delivered;
delivered.push({ id, progress: result.progress });
@@ -222,11 +222,11 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistry
// The heartbeat lets a slow batch outlive STALE_CLAIM_THRESHOLD_MS without being delivered twice.
const $handleClaimed = async (
- consumer: IEventOutboxConsumer,
+ consumer: IEventConsumer,
key: TOutboxFlushKey,
claimed: TEventOutbox[],
lockToken: string
- ): Promise<TOutboxEventResult[]> => {
+ ): Promise<TEventConsumerResult[]> => {
const ids = claimed.map((row) => String(row.id));
const heartbeat = setInterval(() => {
eventOutboxDAL.extendClaims(ids, lockToken).catch((error) => {
diff --git a/backend/src/services/event-outbox/event-outbox-types.ts b/backend/src/services/event-outbox/event-outbox-types.ts
index f5bcef85af..3d1796cf8c 100644
--- a/backend/src/services/event-outbox/event-outbox-types.ts
+++ b/backend/src/services/event-outbox/event-outbox-types.ts
@@ -62,7 +62,7 @@ export const OutboxEventSchema = z.object({
export type TOutboxEvent = z.input<typeof OutboxEventSchema>;
-export type TOutboxEventResult = {
+export type TEventConsumerResult = {
id: string;
status: EventOutboxStatus.Delivered | EventOutboxStatus.Retry | EventOutboxStatus.Failed;
error?: string;
@@ -76,7 +76,7 @@ export type TOutboxFlushKey = {
resourceId: string;
};
-export interface IEventOutboxConsumer<TPayload = unknown> {
+export interface IEventConsumer<TPayload = unknown> {
// Stored on every row and part of the flush job id, so renaming it orphans in-flight rows.
name: string;
@@ -89,5 +89,5 @@ export interface IEventOutboxConsumer<TPayload = unknown> {
subscribesTo(eventType: string): boolean;
// Events for a single (resourceType, resourceId), in id order. Must return one result per event.
- handle(events: TEventOutbox[]): Promise<TOutboxEventResult[]>;
+ handle(events: TEventOutbox[]): Promise<TEventConsumerResult[]>;
}