@event-driven-io/emmett 0.43.0-beta.15 → 0.43.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -812,8 +812,8 @@ declare class AssertionError extends Error {
812
812
  }
813
813
  declare const isSubset: (superObj: unknown, subObj: unknown) => boolean;
814
814
  declare const assertFails: (message?: string) => never;
815
- declare const assertThrowsAsync: <TError extends Error>(fun: () => Promise<unknown>, errorCheck?: (error: Error) => boolean) => Promise<TError>;
816
- declare const assertThrows: <TError extends Error>(fun: () => void, errorCheck?: (error: Error) => boolean) => TError;
815
+ declare const assertThrowsAsync: <TError extends Error>(fun: () => Promise<unknown>, errorCheck?: (error: TError) => boolean) => Promise<TError>;
816
+ declare const assertThrows: <TError extends Error>(fun: () => void, errorCheck?: (error: TError) => boolean) => TError;
817
817
  declare const assertDoesNotThrow: <TError extends Error>(fun: () => void, errorCheck?: (error: Error) => boolean) => TError | null;
818
818
  declare const assertRejects: <T, TError extends Error = Error>(promise: Promise<T>, errorCheck?: ((error: TError) => boolean) | TError) => Promise<void>;
819
819
  declare const assertMatches: (actual: unknown, expected: unknown, message?: string) => void;
package/dist/index.d.ts CHANGED
@@ -812,8 +812,8 @@ declare class AssertionError extends Error {
812
812
  }
813
813
  declare const isSubset: (superObj: unknown, subObj: unknown) => boolean;
814
814
  declare const assertFails: (message?: string) => never;
815
- declare const assertThrowsAsync: <TError extends Error>(fun: () => Promise<unknown>, errorCheck?: (error: Error) => boolean) => Promise<TError>;
816
- declare const assertThrows: <TError extends Error>(fun: () => void, errorCheck?: (error: Error) => boolean) => TError;
815
+ declare const assertThrowsAsync: <TError extends Error>(fun: () => Promise<unknown>, errorCheck?: (error: TError) => boolean) => Promise<TError>;
816
+ declare const assertThrows: <TError extends Error>(fun: () => void, errorCheck?: (error: TError) => boolean) => TError;
817
817
  declare const assertDoesNotThrow: <TError extends Error>(fun: () => void, errorCheck?: (error: Error) => boolean) => TError | null;
818
818
  declare const assertRejects: <T, TError extends Error = Error>(promise: Promise<T>, errorCheck?: ((error: TError) => boolean) | TError) => Promise<void>;
819
819
  declare const assertMatches: (actual: unknown, expected: unknown, message?: string) => void;
package/dist/index.js CHANGED
@@ -1069,14 +1069,27 @@ const reactor = (options) => {
1069
1069
  canHandle,
1070
1070
  init,
1071
1071
  start: async (startOptions) => {
1072
- if (isActive) return;
1072
+ if (isActive) {
1073
+ console.log(`Processor ${processorId} with instance id ${instanceId} is already active. Start request ignored.`);
1074
+ return;
1075
+ }
1076
+ console.log(`Starting processor ${processorId} with instance id ${instanceId}`);
1073
1077
  await init(startOptions);
1074
1078
  isActive = true;
1075
1079
  closeSignal = onShutdown(() => close(startOptions));
1076
- if (lastCheckpoint !== null) return { lastCheckpoint };
1080
+ if (lastCheckpoint !== null) {
1081
+ console.log(`Processor ${processorId} started with instance id ${instanceId}, checkpoint: ${JSONSerializer.serialize(lastCheckpoint)}`);
1082
+ return { lastCheckpoint };
1083
+ }
1077
1084
  return await processingScope(async (context) => {
1078
- if (hooks.onStart) await hooks.onStart(context);
1079
- if (startFrom && startFrom !== "CURRENT") return startFrom;
1085
+ if (hooks.onStart) {
1086
+ console.log(`Executing onStart hook for processor ${processorId} with instance id ${instanceId}`);
1087
+ await hooks.onStart(context);
1088
+ }
1089
+ if (startFrom && startFrom !== "CURRENT") {
1090
+ console.log(`Processor ${processorId} with instance id ${instanceId} starting from: ${JSONSerializer.serialize(startFrom)}`);
1091
+ return startFrom;
1092
+ }
1080
1093
  if (checkpoints) lastCheckpoint = (await checkpoints?.read({
1081
1094
  processorId,
1082
1095
  partition
@@ -1084,7 +1097,11 @@ const reactor = (options) => {
1084
1097
  ...startOptions,
1085
1098
  ...context
1086
1099
  })).lastCheckpoint;
1087
- if (lastCheckpoint === null) return "BEGINNING";
1100
+ if (lastCheckpoint === null) {
1101
+ console.log(`Processor ${processorId} with instance id ${instanceId} starting from: BEGINNING`);
1102
+ return "BEGINNING";
1103
+ }
1104
+ console.log(`Checkpoint read for processor ${processorId} with instance id ${instanceId}: ${JSONSerializer.serialize(lastCheckpoint)}`);
1088
1105
  return { lastCheckpoint };
1089
1106
  }, startOptions);
1090
1107
  },
@@ -1094,34 +1111,44 @@ const reactor = (options) => {
1094
1111
  },
1095
1112
  handle: async (messages, partialContext) => {
1096
1113
  if (!isActive) return Promise.resolve();
1097
- return await processingScope(async (context) => {
1098
- const messagesAboveCheckpoint = messages.filter((message) => !wasMessageHandled(message, lastCheckpoint));
1099
- const upcastedMessages = messagesAboveCheckpoint.map((message) => upcastRecordedMessage(message, options.messageOptions?.schema?.versioning)).filter((upcasted) => !canHandle || canHandle.includes(upcasted.type));
1100
- const stopMessageIndex = isCustomBatch && stopAfter ? upcastedMessages.findIndex(stopAfter) : -1;
1101
- const unhandledMessages = stopMessageIndex !== -1 ? upcastedMessages.slice(0, stopMessageIndex + 1) : upcastedMessages;
1102
- const batchResult = await eachBatch(unhandledMessages, context);
1103
- const messageProcessingResult = batchResult?.type === "STOP" ? batchResult : stopMessageIndex !== -1 ? {
1114
+ try {
1115
+ return await processingScope(async (context) => {
1116
+ const messagesAboveCheckpoint = messages.filter((message) => !wasMessageHandled(message, lastCheckpoint));
1117
+ const upcastedMessages = messagesAboveCheckpoint.map((message) => upcastRecordedMessage(message, options.messageOptions?.schema?.versioning)).filter((upcasted) => !canHandle || canHandle.includes(upcasted.type));
1118
+ const stopMessageIndex = isCustomBatch && stopAfter ? upcastedMessages.findIndex(stopAfter) : -1;
1119
+ const unhandledMessages = stopMessageIndex !== -1 ? upcastedMessages.slice(0, stopMessageIndex + 1) : upcastedMessages;
1120
+ const batchResult = await eachBatch(unhandledMessages, context);
1121
+ const messageProcessingResult = batchResult?.type === "STOP" ? batchResult : stopMessageIndex !== -1 ? {
1122
+ type: "STOP",
1123
+ reason: "Stop condition reached",
1124
+ lastSuccessfulMessage: unhandledMessages[stopMessageIndex]
1125
+ } : batchResult;
1126
+ const isStop = messageProcessingResult && messageProcessingResult.type === "STOP";
1127
+ const checkpointMessage = messageProcessingResult?.type === "STOP" ? messageProcessingResult.lastSuccessfulMessage : messagesAboveCheckpoint[messagesAboveCheckpoint.length - 1];
1128
+ if (checkpointMessage && checkpoints) {
1129
+ const storeCheckpointResult = await checkpoints.store({
1130
+ processorId,
1131
+ version,
1132
+ message: checkpointMessage,
1133
+ lastCheckpoint,
1134
+ partition
1135
+ }, context);
1136
+ if (storeCheckpointResult.success) lastCheckpoint = storeCheckpointResult.newCheckpoint;
1137
+ }
1138
+ if (isStop) {
1139
+ isActive = false;
1140
+ return messageProcessingResult;
1141
+ }
1142
+ }, partialContext);
1143
+ } catch (error) {
1144
+ console.log(`Error during message processing for processor ${processorId} with instance id ${instanceId}. Stopping the processor.`, error);
1145
+ isActive = false;
1146
+ return {
1104
1147
  type: "STOP",
1105
- reason: "Stop condition reached",
1106
- lastSuccessfulMessage: unhandledMessages[stopMessageIndex]
1107
- } : batchResult;
1108
- const isStop = messageProcessingResult && messageProcessingResult.type === "STOP";
1109
- const checkpointMessage = messageProcessingResult?.type === "STOP" ? messageProcessingResult.lastSuccessfulMessage : messagesAboveCheckpoint[messagesAboveCheckpoint.length - 1];
1110
- if (checkpointMessage && checkpoints) {
1111
- const storeCheckpointResult = await checkpoints.store({
1112
- processorId,
1113
- version,
1114
- message: checkpointMessage,
1115
- lastCheckpoint,
1116
- partition
1117
- }, context);
1118
- if (storeCheckpointResult.success) lastCheckpoint = storeCheckpointResult.newCheckpoint;
1119
- }
1120
- if (isStop) {
1121
- isActive = false;
1122
- return messageProcessingResult;
1123
- }
1124
- }, partialContext);
1148
+ error,
1149
+ reason: "Error during message processing"
1150
+ };
1151
+ }
1125
1152
  }
1126
1153
  };
1127
1154
  };