@event-driven-io/emmett 0.42.0 → 0.42.1-alpha.1

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.cjs CHANGED
@@ -1992,19 +1992,39 @@ var reactor = (options) => {
1992
1992
  type,
1993
1993
  init,
1994
1994
  start: async (startOptions) => {
1995
- if (isActive) return;
1995
+ if (isActive) {
1996
+ console.log(
1997
+ `Processor ${processorId} with instance id ${instanceId} is already active. Start request ignored.`
1998
+ );
1999
+ return;
2000
+ }
2001
+ console.log(
2002
+ `Starting processor ${processorId} with instance id ${instanceId}`
2003
+ );
1996
2004
  await init(startOptions);
1997
2005
  isActive = true;
1998
2006
  closeSignal = onShutdown(() => close({}));
1999
- if (lastCheckpoint !== null)
2007
+ if (lastCheckpoint !== null) {
2008
+ console.log(
2009
+ `Processor ${processorId} started with instance id ${instanceId}, checkpoint: ${JSONParser.stringify(lastCheckpoint)}`
2010
+ );
2000
2011
  return {
2001
2012
  lastCheckpoint
2002
2013
  };
2014
+ }
2003
2015
  return await processingScope(async (context) => {
2004
2016
  if (hooks.onStart) {
2017
+ console.log(
2018
+ `Executing onStart hook for processor ${processorId} with instance id ${instanceId}`
2019
+ );
2005
2020
  await hooks.onStart(context);
2006
2021
  }
2007
- if (startFrom && startFrom !== "CURRENT") return startFrom;
2022
+ if (startFrom && startFrom !== "CURRENT") {
2023
+ console.log(
2024
+ `Processor ${processorId} with instance id ${instanceId} starting from: ${JSONParser.stringify(startFrom)}`
2025
+ );
2026
+ return startFrom;
2027
+ }
2008
2028
  if (checkpoints) {
2009
2029
  const readResult = await _optionalChain([checkpoints, 'optionalAccess', _98 => _98.read, 'call', _99 => _99(
2010
2030
  {
@@ -2015,7 +2035,15 @@ var reactor = (options) => {
2015
2035
  )]);
2016
2036
  lastCheckpoint = readResult.lastCheckpoint;
2017
2037
  }
2018
- if (lastCheckpoint === null) return "BEGINNING";
2038
+ if (lastCheckpoint === null) {
2039
+ console.log(
2040
+ `Processor ${processorId} with instance id ${instanceId} starting from: BEGINNING`
2041
+ );
2042
+ return "BEGINNING";
2043
+ }
2044
+ console.log(
2045
+ `Checkpoint read for processor ${processorId} with instance id ${instanceId}: ${JSONParser.stringify(lastCheckpoint)}`
2046
+ );
2019
2047
  return {
2020
2048
  lastCheckpoint
2021
2049
  };
@@ -2027,48 +2055,64 @@ var reactor = (options) => {
2027
2055
  },
2028
2056
  handle: async (messages, partialContext) => {
2029
2057
  if (!isActive) return Promise.resolve();
2030
- return await processingScope(async (context) => {
2031
- let result = void 0;
2032
- for (const message2 of messages) {
2033
- if (wasMessageHandled(message2, lastCheckpoint)) continue;
2034
- const upcasted = upcastRecordedMessage(
2035
- // TODO: Make it smarter
2036
- message2,
2037
- _optionalChain([options, 'access', _100 => _100.messageOptions, 'optionalAccess', _101 => _101.schema, 'optionalAccess', _102 => _102.versioning])
2038
- );
2039
- if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
2040
- continue;
2041
- const messageProcessingResult = await eachMessage(upcasted, context);
2042
- if (checkpoints) {
2043
- const storeCheckpointResult = await checkpoints.store(
2044
- {
2045
- processorId,
2046
- version,
2047
- message: upcasted,
2048
- lastCheckpoint,
2049
- partition
2050
- },
2058
+ try {
2059
+ return await processingScope(async (context) => {
2060
+ let result = void 0;
2061
+ for (const message2 of messages) {
2062
+ if (wasMessageHandled(message2, lastCheckpoint)) continue;
2063
+ const upcasted = upcastRecordedMessage(
2064
+ // TODO: Make it smarter
2065
+ message2,
2066
+ _optionalChain([options, 'access', _100 => _100.messageOptions, 'optionalAccess', _101 => _101.schema, 'optionalAccess', _102 => _102.versioning])
2067
+ );
2068
+ if (canHandle !== void 0 && !canHandle.includes(upcasted.type))
2069
+ continue;
2070
+ const messageProcessingResult = await eachMessage(
2071
+ upcasted,
2051
2072
  context
2052
2073
  );
2053
- if (storeCheckpointResult.success) {
2054
- lastCheckpoint = storeCheckpointResult.newCheckpoint;
2074
+ if (checkpoints) {
2075
+ const storeCheckpointResult = await checkpoints.store(
2076
+ {
2077
+ processorId,
2078
+ version,
2079
+ message: upcasted,
2080
+ lastCheckpoint,
2081
+ partition
2082
+ },
2083
+ context
2084
+ );
2085
+ if (storeCheckpointResult.success) {
2086
+ lastCheckpoint = storeCheckpointResult.newCheckpoint;
2087
+ }
2055
2088
  }
2089
+ if (messageProcessingResult && messageProcessingResult.type === "STOP") {
2090
+ isActive = false;
2091
+ result = messageProcessingResult;
2092
+ break;
2093
+ }
2094
+ if (stopAfter && stopAfter(upcasted)) {
2095
+ isActive = false;
2096
+ result = { type: "STOP", reason: "Stop condition reached" };
2097
+ break;
2098
+ }
2099
+ if (messageProcessingResult && messageProcessingResult.type === "SKIP")
2100
+ continue;
2056
2101
  }
2057
- if (messageProcessingResult && messageProcessingResult.type === "STOP") {
2058
- isActive = false;
2059
- result = messageProcessingResult;
2060
- break;
2061
- }
2062
- if (stopAfter && stopAfter(upcasted)) {
2063
- isActive = false;
2064
- result = { type: "STOP", reason: "Stop condition reached" };
2065
- break;
2066
- }
2067
- if (messageProcessingResult && messageProcessingResult.type === "SKIP")
2068
- continue;
2069
- }
2070
- return result;
2071
- }, partialContext);
2102
+ return result;
2103
+ }, partialContext);
2104
+ } catch (error2) {
2105
+ console.log(
2106
+ `Error during message processing for processor ${processorId} with instance id ${instanceId}. Stopping the processor.`,
2107
+ error2
2108
+ );
2109
+ isActive = false;
2110
+ return {
2111
+ type: "STOP",
2112
+ error: error2,
2113
+ reason: "Error during message processing"
2114
+ };
2115
+ }
2072
2116
  }
2073
2117
  };
2074
2118
  };