@machinemetrics/mm-erp-sdk 0.1.7-beta.0 → 0.1.7-beta.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.
@@ -1 +1 @@
1
- {"version":3,"file":"data-sync-service.d.ts","sourceRoot":"","sources":["../../../src/services/data-sync-service/data-sync-service.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,kBAAkB,GAAU,eAAe,MAAM,kBAuG7D,CAAC"}
1
+ {"version":3,"file":"data-sync-service.d.ts","sourceRoot":"","sources":["../../../src/services/data-sync-service/data-sync-service.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,kBAAkB,GAAU,eAAe,MAAM,kBA+I7D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"from-erp.d.ts","sourceRoot":"","sources":["../../../../src/services/data-sync-service/jobs/from-erp.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AASvB,QAAA,MAAM,IAAI,qBAkCT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"from-erp.d.ts","sourceRoot":"","sources":["../../../../src/services/data-sync-service/jobs/from-erp.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAqBvB,QAAA,MAAM,IAAI,qBAmDT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
@@ -3,6 +3,15 @@ import { l as logger } from "../../../logger-Db8CkwR6.js";
3
3
  import { S as SQLiteCoordinator } from "../../../index-B9wo8pld.js";
4
4
  import { c as createConnectorFromPath } from "../../../connector-factory-C2czCs9v.js";
5
5
  logger.level = process.env.LOG_LEVEL || "info";
6
+ if (global.gc) {
7
+ process.on("exit", () => {
8
+ logger.debug("from-erp: Running garbage collection on exit");
9
+ try {
10
+ global.gc?.();
11
+ } catch (e) {
12
+ }
13
+ });
14
+ }
6
15
  const main = async () => {
7
16
  try {
8
17
  logger.info('Worker for job "from-erp" online');
@@ -17,6 +26,17 @@ const main = async () => {
17
26
  });
18
27
  await connector.syncFromERPCompleted();
19
28
  logger.info("==========Completed from-erp job cycle==========");
29
+ logger.debug("from-erp: Starting cleanup sequence");
30
+ if (global.gc) {
31
+ logger.debug("from-erp: Running manual garbage collection");
32
+ try {
33
+ global.gc?.();
34
+ } catch (e) {
35
+ logger.debug("from-erp: GC not available or failed");
36
+ }
37
+ }
38
+ await new Promise((resolve) => setTimeout(resolve, 100));
39
+ logger.debug("from-erp: Cleanup sequence completed");
20
40
  } catch (error) {
21
41
  const errorDetails = {
22
42
  message: error instanceof Error ? error.message : String(error),
@@ -32,10 +52,7 @@ const main = async () => {
32
52
  }
33
53
  };
34
54
  const normalizedArgv1 = process.argv[1].replace(/\\/g, "/");
35
- const fileUrl = normalizedArgv1.startsWith("/") ? `file://${normalizedArgv1}` : (
36
- // Unix: file:// + /path = file:///path
37
- `file:///${normalizedArgv1}`
38
- );
55
+ const fileUrl = normalizedArgv1.startsWith("/") ? `file://${normalizedArgv1}` : `file:///${normalizedArgv1}`;
39
56
  const isMainModule = import.meta.url === fileUrl;
40
57
  if (isMainModule) {
41
58
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"from-erp.js","sources":["../../../../src/services/data-sync-service/jobs/from-erp.ts"],"sourcesContent":["import \"dotenv/config\";\n\nimport logger from \"../../../services/reporting-service/logger\";\nimport { SQLiteCoordinator } from \"../../sqlite-service\";\nimport { createConnectorFromPath } from \"../../../utils/connector-factory\";\n\n// Configure the logger with the correct log level\nlogger.level = process.env.LOG_LEVEL || \"info\";\n\nconst main = async () => {\n try {\n logger.info('Worker for job \"from-erp\" online');\n logger.info(\"==========Starting from-erp job cycle==========\");\n\n // Get the connector path from the environment variable\n const connectorPath = process.env.CONNECTOR_PATH;\n \n if (!connectorPath) {\n throw new Error(\"Connector path not provided in environment variables\");\n }\n\n // Create a new connector instance for this job\n const connector = await createConnectorFromPath(connectorPath);\n\n await SQLiteCoordinator.executeWithLock(\"from-erp\", async () => {\n await connector.syncFromERP();\n });\n\n await connector.syncFromERPCompleted();\n logger.info(\"==========Completed from-erp job cycle==========\");\n } catch (error) {\n const errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n name: error instanceof Error ? error.name : undefined,\n ...(error && typeof error === \"object\" ? error : {}), // Include all enumerable properties if it's an object\n };\n logger.error('Worker for job \"from-erp\" had an error', {\n error: errorDetails,\n });\n\n throw error; // Rethrow so Bree can handle it properly\n }\n};\n\n// Cross-platform module detection fix for Bree compatibility\n// Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes\n// Linux/Mac: both use forward slashes, so this normalization is safe\nconst normalizedArgv1 = process.argv[1].replace(/\\\\/g, '/');\nconst fileUrl = normalizedArgv1.startsWith('/') ? \n `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path\n `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path\nconst isMainModule = import.meta.url === fileUrl;\n\nif (isMainModule) {\n // This is called when Bree runs this file as a worker\n try {\n await main();\n } catch {\n process.exitCode = 1; // prefer exitCode so stdout/stderr can flush\n }\n}\n\nexport default main;"],"names":[],"mappings":";;;;AAOA,OAAO,QAAQ,QAAQ,IAAI,aAAa;AAExC,MAAM,OAAO,YAAY;AACvB,MAAI;AACF,WAAO,KAAK,kCAAkC;AAC9C,WAAO,KAAK,iDAAiD;AAG7D,UAAM,gBAAgB,QAAQ,IAAI;AAElC,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAGA,UAAM,YAAY,MAAM,wBAAwB,aAAa;AAE7D,UAAM,kBAAkB,gBAAgB,YAAY,YAAY;AAC9D,YAAM,UAAU,YAAA;AAAA,IAClB,CAAC;AAED,UAAM,UAAU,qBAAA;AAChB,WAAO,KAAK,kDAAkD;AAAA,EAChE,SAAS,OAAO;AACd,UAAM,eAAe;AAAA,MACnB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,MAC9C,MAAM,iBAAiB,QAAQ,MAAM,OAAO;AAAA,MAC5C,GAAI,SAAS,OAAO,UAAU,WAAW,QAAQ,CAAA;AAAA;AAAA,IAAC;AAEpD,WAAO,MAAM,0CAA0C;AAAA,MACrD,OAAO;AAAA,IAAA,CACR;AAED,UAAM;AAAA,EACR;AACF;AAKA,MAAM,kBAAkB,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC1D,MAAM,UAAU,gBAAgB,WAAW,GAAG,IAC5C,UAAU,eAAe;AAAA;AAAA,EACzB,WAAW,eAAe;AAAA;AAC5B,MAAM,eAAe,YAAY,QAAQ;AAEzC,IAAI,cAAc;AAEhB,MAAI;AACF,UAAM,KAAA;AAAA,EACR,QAAQ;AACN,YAAQ,WAAW;AAAA,EACrB;AACF;"}
1
+ {"version":3,"file":"from-erp.js","sources":["../../../../src/services/data-sync-service/jobs/from-erp.ts"],"sourcesContent":["import \"dotenv/config\";\n\nimport logger from \"../../../services/reporting-service/logger\";\nimport { SQLiteCoordinator } from \"../../sqlite-service\";\nimport { createConnectorFromPath } from \"../../../utils/connector-factory\";\n\n// Configure the logger with the correct log level\nlogger.level = process.env.LOG_LEVEL || \"info\";\n\n// Enable garbage collection on exit if available\nif (global.gc) {\n process.on(\"exit\", () => {\n logger.debug(\"from-erp: Running garbage collection on exit\");\n try {\n global.gc?.();\n } catch (e) {\n // Ignore GC errors\n }\n });\n}\n\nconst main = async () => {\n try {\n logger.info('Worker for job \"from-erp\" online');\n logger.info(\"==========Starting from-erp job cycle==========\");\n\n // Get the connector path from the environment variable\n const connectorPath = process.env.CONNECTOR_PATH;\n\n if (!connectorPath) {\n throw new Error(\"Connector path not provided in environment variables\");\n }\n\n // Create a new connector instance for this job\n const connector = await createConnectorFromPath(connectorPath);\n\n await SQLiteCoordinator.executeWithLock(\"from-erp\", async () => {\n await connector.syncFromERP();\n });\n\n await connector.syncFromERPCompleted();\n logger.info(\"==========Completed from-erp job cycle==========\");\n\n // Cleanup before worker exit\n logger.debug(\"from-erp: Starting cleanup sequence\");\n\n // Trigger garbage collection if available\n if (global.gc) {\n logger.debug(\"from-erp: Running manual garbage collection\");\n try {\n global.gc?.();\n } catch (e) {\n logger.debug(\"from-erp: GC not available or failed\");\n }\n }\n\n // Small delay to allow any pending operations to complete\n await new Promise((resolve) => setTimeout(resolve, 100));\n logger.debug(\"from-erp: Cleanup sequence completed\");\n } catch (error) {\n const errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n name: error instanceof Error ? error.name : undefined,\n ...(error && typeof error === \"object\" ? error : {}), // Include all enumerable properties if it's an object\n };\n logger.error('Worker for job \"from-erp\" had an error', {\n error: errorDetails,\n });\n\n throw error; // Rethrow so Bree can handle it properly\n }\n};\n\n// Cross-platform module detection fix for Bree compatibility\n// Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes\n// Linux/Mac: both use forward slashes, so this normalization is safe\nconst normalizedArgv1 = process.argv[1].replace(/\\\\/g, \"/\");\nconst fileUrl = normalizedArgv1.startsWith(\"/\")\n ? `file://${normalizedArgv1}` // Unix: file:// + /path = file:///path\n : `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path\nconst isMainModule = import.meta.url === fileUrl;\n\nif (isMainModule) {\n // This is called when Bree runs this file as a worker\n try {\n await main();\n } catch {\n process.exitCode = 1; // prefer exitCode so stdout/stderr can flush\n }\n}\n\nexport default main;\n"],"names":[],"mappings":";;;;AAOA,OAAO,QAAQ,QAAQ,IAAI,aAAa;AAGxC,IAAI,OAAO,IAAI;AACb,UAAQ,GAAG,QAAQ,MAAM;AACvB,WAAO,MAAM,8CAA8C;AAC3D,QAAI;AACF,aAAO,KAAA;AAAA,IACT,SAAS,GAAG;AAAA,IAEZ;AAAA,EACF,CAAC;AACH;AAEA,MAAM,OAAO,YAAY;AACvB,MAAI;AACF,WAAO,KAAK,kCAAkC;AAC9C,WAAO,KAAK,iDAAiD;AAG7D,UAAM,gBAAgB,QAAQ,IAAI;AAElC,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAGA,UAAM,YAAY,MAAM,wBAAwB,aAAa;AAE7D,UAAM,kBAAkB,gBAAgB,YAAY,YAAY;AAC9D,YAAM,UAAU,YAAA;AAAA,IAClB,CAAC;AAED,UAAM,UAAU,qBAAA;AAChB,WAAO,KAAK,kDAAkD;AAG9D,WAAO,MAAM,qCAAqC;AAGlD,QAAI,OAAO,IAAI;AACb,aAAO,MAAM,6CAA6C;AAC1D,UAAI;AACF,eAAO,KAAA;AAAA,MACT,SAAS,GAAG;AACV,eAAO,MAAM,sCAAsC;AAAA,MACrD;AAAA,IACF;AAGA,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG,CAAC;AACvD,WAAO,MAAM,sCAAsC;AAAA,EACrD,SAAS,OAAO;AACd,UAAM,eAAe;AAAA,MACnB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,MAC9C,MAAM,iBAAiB,QAAQ,MAAM,OAAO;AAAA,MAC5C,GAAI,SAAS,OAAO,UAAU,WAAW,QAAQ,CAAA;AAAA;AAAA,IAAC;AAEpD,WAAO,MAAM,0CAA0C;AAAA,MACrD,OAAO;AAAA,IAAA,CACR;AAED,UAAM;AAAA,EACR;AACF;AAKA,MAAM,kBAAkB,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC1D,MAAM,UAAU,gBAAgB,WAAW,GAAG,IAC1C,UAAU,eAAe,KACzB,WAAW,eAAe;AAC9B,MAAM,eAAe,YAAY,QAAQ;AAEzC,IAAI,cAAc;AAEhB,MAAI;AACF,UAAM,KAAA;AAAA,EACR,QAAQ;AACN,YAAQ,WAAW;AAAA,EACrB;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"to-erp.d.ts","sourceRoot":"","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AASvB,QAAA,MAAM,IAAI,qBAoCT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"to-erp.d.ts","sourceRoot":"","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAqBvB,QAAA,MAAM,IAAI,qBAqDT,CAAC;AAoBF,eAAe,IAAI,CAAC"}
@@ -2,6 +2,15 @@ import "../../../config-qat9zgOl.js";
2
2
  import { l as logger } from "../../../logger-Db8CkwR6.js";
3
3
  import { c as createConnectorFromPath } from "../../../connector-factory-C2czCs9v.js";
4
4
  logger.level = process.env.LOG_LEVEL || "info";
5
+ if (global.gc) {
6
+ process.on("exit", () => {
7
+ logger.debug("to-erp: Running garbage collection on exit");
8
+ try {
9
+ global.gc?.();
10
+ } catch (e) {
11
+ }
12
+ });
13
+ }
5
14
  const main = async () => {
6
15
  try {
7
16
  logger.info('Worker for job "to-erp" online');
@@ -14,6 +23,17 @@ const main = async () => {
14
23
  await connector.syncToERP();
15
24
  await connector.syncToERPCompleted();
16
25
  logger.info("==========Completed to-erp job cycle==========");
26
+ logger.debug("to-erp: Starting cleanup sequence");
27
+ if (global.gc) {
28
+ logger.debug("to-erp: Running manual garbage collection");
29
+ try {
30
+ global.gc?.();
31
+ } catch (e) {
32
+ logger.debug("to-erp: GC not available or failed");
33
+ }
34
+ }
35
+ await new Promise((resolve) => setTimeout(resolve, 100));
36
+ logger.debug("to-erp: Cleanup sequence completed");
17
37
  } catch (error) {
18
38
  const errorDetails = {
19
39
  message: error instanceof Error ? error.message : String(error),
@@ -31,10 +51,7 @@ const main = async () => {
31
51
  }
32
52
  };
33
53
  const normalizedArgv1 = process.argv[1].replace(/\\/g, "/");
34
- const fileUrl = normalizedArgv1.startsWith("/") ? `file://${normalizedArgv1}` : (
35
- // Unix: file:// + /path = file:///path
36
- `file:///${normalizedArgv1}`
37
- );
54
+ const fileUrl = normalizedArgv1.startsWith("/") ? `file://${normalizedArgv1}` : `file:///${normalizedArgv1}`;
38
55
  const isMainModule = import.meta.url === fileUrl;
39
56
  if (isMainModule) {
40
57
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"to-erp.js","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"sourcesContent":["import \"dotenv/config\";\n\nimport logger from \"../../../services/reporting-service/logger\";\nimport { SQLiteCoordinator } from \"../../sqlite-service\";\nimport { createConnectorFromPath } from \"../../../utils/connector-factory\";\n\n// Configure the logger with the correct log level\nlogger.level = process.env.LOG_LEVEL || \"info\";\n\nconst main = async () => {\n try {\n logger.info('Worker for job \"to-erp\" online');\n logger.info(\"==========Starting to-erp job cycle==========\");\n\n // Get the connector path from the environment variable\n const connectorPath = process.env.CONNECTOR_PATH;\n\n if (!connectorPath) {\n throw new Error(\"Connector path not provided in environment variables\");\n }\n\n // Create a new connector instance for this job\n const connector = await createConnectorFromPath(connectorPath);\n\n await connector.syncToERP();\n await connector.syncToERPCompleted();\n\n logger.info(\"==========Completed to-erp job cycle==========\");\n } catch (error) {\n const errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n name: error instanceof Error ? error.name : undefined,\n ...(error && typeof error === \"object\" ? error : {}), // Include all enumerable properties if it's an object\n };\n logger.error('Worker for job \"to-erp\" had an error', {\n error: errorDetails,\n connectorPath: process.env.CONNECTOR_PATH,\n });\n\n // Also log to console for immediate visibility\n console.error(\"to-erp job error:\", error);\n\n throw error; // Rethrow so Bree can handle it properly\n }\n};\n\n// Cross-platform module detection fix for Bree compatibility\n// Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes\n// Linux/Mac: both use forward slashes, so this normalization is safe\nconst normalizedArgv1 = process.argv[1].replace(/\\\\/g, '/');\nconst fileUrl = normalizedArgv1.startsWith('/') ? \n `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path\n `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path\nconst isMainModule = import.meta.url === fileUrl;\n\nif (isMainModule) {\n // This is called when Bree runs this file as a worker\n try {\n await main();\n } catch {\n process.exitCode = 1; // prefer exitCode so stdout/stderr can flush\n }\n}\n\nexport default main;\n"],"names":[],"mappings":";;;AAOA,OAAO,QAAQ,QAAQ,IAAI,aAAa;AAExC,MAAM,OAAO,YAAY;AACvB,MAAI;AACF,WAAO,KAAK,gCAAgC;AAC5C,WAAO,KAAK,+CAA+C;AAG3D,UAAM,gBAAgB,QAAQ,IAAI;AAElC,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAGA,UAAM,YAAY,MAAM,wBAAwB,aAAa;AAE7D,UAAM,UAAU,UAAA;AAChB,UAAM,UAAU,mBAAA;AAEhB,WAAO,KAAK,gDAAgD;AAAA,EAC9D,SAAS,OAAO;AACd,UAAM,eAAe;AAAA,MACnB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,MAC9C,MAAM,iBAAiB,QAAQ,MAAM,OAAO;AAAA,MAC5C,GAAI,SAAS,OAAO,UAAU,WAAW,QAAQ,CAAA;AAAA;AAAA,IAAC;AAEpD,WAAO,MAAM,wCAAwC;AAAA,MACnD,OAAO;AAAA,MACP,eAAe,QAAQ,IAAI;AAAA,IAAA,CAC5B;AAGD,YAAQ,MAAM,qBAAqB,KAAK;AAExC,UAAM;AAAA,EACR;AACF;AAKA,MAAM,kBAAkB,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC1D,MAAM,UAAU,gBAAgB,WAAW,GAAG,IAC5C,UAAU,eAAe;AAAA;AAAA,EACzB,WAAW,eAAe;AAAA;AAC5B,MAAM,eAAe,YAAY,QAAQ;AAEzC,IAAI,cAAc;AAEhB,MAAI;AACF,UAAM,KAAA;AAAA,EACR,QAAQ;AACN,YAAQ,WAAW;AAAA,EACrB;AACF;"}
1
+ {"version":3,"file":"to-erp.js","sources":["../../../../src/services/data-sync-service/jobs/to-erp.ts"],"sourcesContent":["import \"dotenv/config\";\n\nimport logger from \"../../../services/reporting-service/logger\";\nimport { SQLiteCoordinator } from \"../../sqlite-service\";\nimport { createConnectorFromPath } from \"../../../utils/connector-factory\";\n\n// Configure the logger with the correct log level\nlogger.level = process.env.LOG_LEVEL || \"info\";\n\n// Enable garbage collection on exit if available\nif (global.gc) {\n process.on(\"exit\", () => {\n logger.debug(\"to-erp: Running garbage collection on exit\");\n try {\n global.gc?.();\n } catch (e) {\n // Ignore GC errors\n }\n });\n}\n\nconst main = async () => {\n try {\n logger.info('Worker for job \"to-erp\" online');\n logger.info(\"==========Starting to-erp job cycle==========\");\n\n // Get the connector path from the environment variable\n const connectorPath = process.env.CONNECTOR_PATH;\n\n if (!connectorPath) {\n throw new Error(\"Connector path not provided in environment variables\");\n }\n\n // Create a new connector instance for this job\n const connector = await createConnectorFromPath(connectorPath);\n\n await connector.syncToERP();\n await connector.syncToERPCompleted();\n\n logger.info(\"==========Completed to-erp job cycle==========\");\n\n // Cleanup before worker exit\n logger.debug(\"to-erp: Starting cleanup sequence\");\n\n // Trigger garbage collection if available\n if (global.gc) {\n logger.debug(\"to-erp: Running manual garbage collection\");\n try {\n global.gc?.();\n } catch (e) {\n logger.debug(\"to-erp: GC not available or failed\");\n }\n }\n\n // Small delay to allow any pending operations to complete\n await new Promise((resolve) => setTimeout(resolve, 100));\n logger.debug(\"to-erp: Cleanup sequence completed\");\n } catch (error) {\n const errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n name: error instanceof Error ? error.name : undefined,\n ...(error && typeof error === \"object\" ? error : {}), // Include all enumerable properties if it's an object\n };\n logger.error('Worker for job \"to-erp\" had an error', {\n error: errorDetails,\n connectorPath: process.env.CONNECTOR_PATH,\n });\n\n // Also log to console for immediate visibility\n console.error(\"to-erp job error:\", error);\n\n throw error; // Rethrow so Bree can handle it properly\n }\n};\n\n// Cross-platform module detection fix for Bree compatibility\n// Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes\n// Linux/Mac: both use forward slashes, so this normalization is safe\nconst normalizedArgv1 = process.argv[1].replace(/\\\\/g, \"/\");\nconst fileUrl = normalizedArgv1.startsWith(\"/\")\n ? `file://${normalizedArgv1}` // Unix: file:// + /path = file:///path\n : `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path\nconst isMainModule = import.meta.url === fileUrl;\n\nif (isMainModule) {\n // This is called when Bree runs this file as a worker\n try {\n await main();\n } catch {\n process.exitCode = 1; // prefer exitCode so stdout/stderr can flush\n }\n}\n\nexport default main;\n"],"names":[],"mappings":";;;AAOA,OAAO,QAAQ,QAAQ,IAAI,aAAa;AAGxC,IAAI,OAAO,IAAI;AACb,UAAQ,GAAG,QAAQ,MAAM;AACvB,WAAO,MAAM,4CAA4C;AACzD,QAAI;AACF,aAAO,KAAA;AAAA,IACT,SAAS,GAAG;AAAA,IAEZ;AAAA,EACF,CAAC;AACH;AAEA,MAAM,OAAO,YAAY;AACvB,MAAI;AACF,WAAO,KAAK,gCAAgC;AAC5C,WAAO,KAAK,+CAA+C;AAG3D,UAAM,gBAAgB,QAAQ,IAAI;AAElC,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAGA,UAAM,YAAY,MAAM,wBAAwB,aAAa;AAE7D,UAAM,UAAU,UAAA;AAChB,UAAM,UAAU,mBAAA;AAEhB,WAAO,KAAK,gDAAgD;AAG5D,WAAO,MAAM,mCAAmC;AAGhD,QAAI,OAAO,IAAI;AACb,aAAO,MAAM,2CAA2C;AACxD,UAAI;AACF,eAAO,KAAA;AAAA,MACT,SAAS,GAAG;AACV,eAAO,MAAM,oCAAoC;AAAA,MACnD;AAAA,IACF;AAGA,UAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG,CAAC;AACvD,WAAO,MAAM,oCAAoC;AAAA,EACnD,SAAS,OAAO;AACd,UAAM,eAAe;AAAA,MACnB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,MAC9D,OAAO,iBAAiB,QAAQ,MAAM,QAAQ;AAAA,MAC9C,MAAM,iBAAiB,QAAQ,MAAM,OAAO;AAAA,MAC5C,GAAI,SAAS,OAAO,UAAU,WAAW,QAAQ,CAAA;AAAA;AAAA,IAAC;AAEpD,WAAO,MAAM,wCAAwC;AAAA,MACnD,OAAO;AAAA,MACP,eAAe,QAAQ,IAAI;AAAA,IAAA,CAC5B;AAGD,YAAQ,MAAM,qBAAqB,KAAK;AAExC,UAAM;AAAA,EACR;AACF;AAKA,MAAM,kBAAkB,QAAQ,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG;AAC1D,MAAM,UAAU,gBAAgB,WAAW,GAAG,IAC1C,UAAU,eAAe,KACzB,WAAW,eAAe;AAC9B,MAAM,eAAe,YAAY,QAAQ;AAEzC,IAAI,cAAc;AAEhB,MAAI;AACF,UAAM,KAAA;AAAA,EACR,QAAQ;AACN,YAAQ,WAAW;AAAA,EACrB;AACF;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-erp-sdk",
3
3
  "description": "A library for syncing data between MachineMetrics and ERP systems",
4
- "version": "0.1.7-beta.0",
4
+ "version": "0.1.7-beta.1",
5
5
  "license": "MIT",
6
6
  "author": "machinemetrics",
7
7
  "main": "dist/mm-erp-sdk.js",
@@ -27,6 +27,9 @@ export const runDataSyncService = async (connectorPath: string) => {
27
27
  const bree = new Bree({
28
28
  root: jobsPath,
29
29
  logger,
30
+ // Enable worker metadata for debugging
31
+ outputWorkerMetadata: true,
32
+
30
33
  worker: {
31
34
  env: {
32
35
  CONNECTOR_PATH: connectorPath,
@@ -42,7 +45,13 @@ export const runDataSyncService = async (connectorPath: string) => {
42
45
  // Pass through all other environment variables that might be needed
43
46
  ...process.env,
44
47
  },
48
+
49
+ // Add worker options for better isolation and cleanup
50
+ execArgv: [
51
+ "--expose-gc", // Allow manual garbage collection
52
+ ],
45
53
  },
54
+
46
55
  jobs: [
47
56
  // {
48
57
  // name: 'run-migrations', // Running this once on startup will create the tables in the sqlite database
@@ -51,19 +60,24 @@ export const runDataSyncService = async (connectorPath: string) => {
51
60
  name: "from-erp",
52
61
  timeout: "10s",
53
62
  interval: config.fromErpInterval,
63
+ // Ensure worker terminates completely after execution
64
+ closeWorkerAfterMs: 1000,
54
65
  },
55
66
  {
56
67
  name: "to-erp",
57
68
  //timeout: '3s', // Use timeout during development to see the job in action quickly
58
69
  interval: config.toErpInterval,
70
+ closeWorkerAfterMs: 1000,
59
71
  },
60
72
  {
61
73
  name: "retry-failed-labor-tickets",
62
74
  interval: config.retryLaborTicketsInterval,
75
+ closeWorkerAfterMs: 1000,
63
76
  },
64
77
  {
65
78
  name: "clean-up-expired-cache",
66
79
  interval: config.cacheExpirationCheckInterval,
80
+ closeWorkerAfterMs: 1000,
67
81
  },
68
82
  ],
69
83
  });
@@ -75,15 +89,41 @@ export const runDataSyncService = async (connectorPath: string) => {
75
89
  name: job.name,
76
90
  interval: job.interval,
77
91
  timeout: job.timeout,
92
+ closeWorkerAfterMs: job.closeWorkerAfterMs,
78
93
  }));
79
94
  logger.info("JOBS CONFIGURATION:", { jobs: jobsConfig });
80
95
 
81
96
  const graceful = new Graceful({ brees: [bree] });
82
97
  graceful.listen();
83
98
 
84
- (async () => {
85
- await bree.start();
86
- })();
99
+ // Enhanced event handlers for debugging worker lifecycle
100
+ bree.on("worker created", (name) => {
101
+ logger.debug(`Worker created for job: ${name}`);
102
+ });
103
+
104
+ bree.on("worker online", (name) => {
105
+ logger.debug(`Worker online for job: ${name}`);
106
+ });
107
+
108
+ bree.on("worker message", (name, message) => {
109
+ logger.debug(`Worker message from ${name}:`, message);
110
+ });
111
+
112
+ bree.on("worker deleted", (name) => {
113
+ logger.debug(`Worker deleted for job: ${name}`);
114
+ });
115
+
116
+ bree.on("worker exit", (name, code, signal) => {
117
+ if (code !== 0) {
118
+ logger.error(
119
+ `Worker ${name} exited with code ${code}, signal ${signal}`
120
+ );
121
+ } else {
122
+ logger.debug(`Worker ${name} exited successfully`);
123
+ }
124
+ });
125
+
126
+ await bree.start();
87
127
 
88
128
  bree.on("jobStarted", (job) => {
89
129
  console.log("Job " + job.name + " started");
@@ -7,6 +7,18 @@ import { createConnectorFromPath } from "../../../utils/connector-factory";
7
7
  // Configure the logger with the correct log level
8
8
  logger.level = process.env.LOG_LEVEL || "info";
9
9
 
10
+ // Enable garbage collection on exit if available
11
+ if (global.gc) {
12
+ process.on("exit", () => {
13
+ logger.debug("from-erp: Running garbage collection on exit");
14
+ try {
15
+ global.gc?.();
16
+ } catch (e) {
17
+ // Ignore GC errors
18
+ }
19
+ });
20
+ }
21
+
10
22
  const main = async () => {
11
23
  try {
12
24
  logger.info('Worker for job "from-erp" online');
@@ -14,7 +26,7 @@ const main = async () => {
14
26
 
15
27
  // Get the connector path from the environment variable
16
28
  const connectorPath = process.env.CONNECTOR_PATH;
17
-
29
+
18
30
  if (!connectorPath) {
19
31
  throw new Error("Connector path not provided in environment variables");
20
32
  }
@@ -28,6 +40,23 @@ const main = async () => {
28
40
 
29
41
  await connector.syncFromERPCompleted();
30
42
  logger.info("==========Completed from-erp job cycle==========");
43
+
44
+ // Cleanup before worker exit
45
+ logger.debug("from-erp: Starting cleanup sequence");
46
+
47
+ // Trigger garbage collection if available
48
+ if (global.gc) {
49
+ logger.debug("from-erp: Running manual garbage collection");
50
+ try {
51
+ global.gc?.();
52
+ } catch (e) {
53
+ logger.debug("from-erp: GC not available or failed");
54
+ }
55
+ }
56
+
57
+ // Small delay to allow any pending operations to complete
58
+ await new Promise((resolve) => setTimeout(resolve, 100));
59
+ logger.debug("from-erp: Cleanup sequence completed");
31
60
  } catch (error) {
32
61
  const errorDetails = {
33
62
  message: error instanceof Error ? error.message : String(error),
@@ -46,10 +75,10 @@ const main = async () => {
46
75
  // Cross-platform module detection fix for Bree compatibility
47
76
  // Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes
48
77
  // Linux/Mac: both use forward slashes, so this normalization is safe
49
- const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');
50
- const fileUrl = normalizedArgv1.startsWith('/') ?
51
- `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path
52
- `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
78
+ const normalizedArgv1 = process.argv[1].replace(/\\/g, "/");
79
+ const fileUrl = normalizedArgv1.startsWith("/")
80
+ ? `file://${normalizedArgv1}` // Unix: file:// + /path = file:///path
81
+ : `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
53
82
  const isMainModule = import.meta.url === fileUrl;
54
83
 
55
84
  if (isMainModule) {
@@ -61,4 +90,4 @@ if (isMainModule) {
61
90
  }
62
91
  }
63
92
 
64
- export default main;
93
+ export default main;
@@ -7,6 +7,18 @@ import { createConnectorFromPath } from "../../../utils/connector-factory";
7
7
  // Configure the logger with the correct log level
8
8
  logger.level = process.env.LOG_LEVEL || "info";
9
9
 
10
+ // Enable garbage collection on exit if available
11
+ if (global.gc) {
12
+ process.on("exit", () => {
13
+ logger.debug("to-erp: Running garbage collection on exit");
14
+ try {
15
+ global.gc?.();
16
+ } catch (e) {
17
+ // Ignore GC errors
18
+ }
19
+ });
20
+ }
21
+
10
22
  const main = async () => {
11
23
  try {
12
24
  logger.info('Worker for job "to-erp" online');
@@ -26,6 +38,23 @@ const main = async () => {
26
38
  await connector.syncToERPCompleted();
27
39
 
28
40
  logger.info("==========Completed to-erp job cycle==========");
41
+
42
+ // Cleanup before worker exit
43
+ logger.debug("to-erp: Starting cleanup sequence");
44
+
45
+ // Trigger garbage collection if available
46
+ if (global.gc) {
47
+ logger.debug("to-erp: Running manual garbage collection");
48
+ try {
49
+ global.gc?.();
50
+ } catch (e) {
51
+ logger.debug("to-erp: GC not available or failed");
52
+ }
53
+ }
54
+
55
+ // Small delay to allow any pending operations to complete
56
+ await new Promise((resolve) => setTimeout(resolve, 100));
57
+ logger.debug("to-erp: Cleanup sequence completed");
29
58
  } catch (error) {
30
59
  const errorDetails = {
31
60
  message: error instanceof Error ? error.message : String(error),
@@ -48,10 +77,10 @@ const main = async () => {
48
77
  // Cross-platform module detection fix for Bree compatibility
49
78
  // Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes
50
79
  // Linux/Mac: both use forward slashes, so this normalization is safe
51
- const normalizedArgv1 = process.argv[1].replace(/\\/g, '/');
52
- const fileUrl = normalizedArgv1.startsWith('/') ?
53
- `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path
54
- `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
80
+ const normalizedArgv1 = process.argv[1].replace(/\\/g, "/");
81
+ const fileUrl = normalizedArgv1.startsWith("/")
82
+ ? `file://${normalizedArgv1}` // Unix: file:// + /path = file:///path
83
+ : `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path
55
84
  const isMainModule = import.meta.url === fileUrl;
56
85
 
57
86
  if (isMainModule) {