@sentio/runtime 2.18.1-rc.2 → 2.18.1-rc.3

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,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import path from 'path';
3
3
  import fs from 'fs-extra';
4
+ import { compressionAlgorithms } from '@grpc/grpc-js';
4
5
  import commandLineArgs from 'command-line-args';
5
6
  import { createServer } from 'nice-grpc';
6
- import { compressionAlgorithms } from '@grpc/grpc-js';
7
- import { register as globalRegistry, Registry } from 'prom-client';
8
7
  import { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus';
8
+ import { register as globalRegistry, Registry } from 'prom-client';
9
9
  import http from 'http';
10
- const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry]);
11
10
  import { ProcessorDefinition } from './gen/processor/protos/processor.js';
12
11
  import { ProcessorServiceImpl } from './service.js';
13
12
  import { Endpoints } from './endpoints.js';
14
13
  import { FullProcessorServiceImpl } from './full-service.js';
15
14
  import { setupJsonLogger } from './logger.js';
15
+ const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry]);
16
16
  const optionDefinitions = [
17
17
  { name: 'target', type: String, defaultOption: true },
18
18
  { name: 'port', alias: 'p', type: String, defaultValue: '4000' },
@@ -89,12 +89,24 @@ const httpServer = http
89
89
  })
90
90
  .listen(metricsPort);
91
91
  console.log('Metric Server Started at:', metricsPort);
92
- process.on('SIGINT', function () {
92
+ process
93
+ .on('SIGINT', function () {
94
+ shutdownServers(0);
95
+ })
96
+ .on('uncaughtException', (err) => {
97
+ console.error('Uncaught Exception, please checking if await is properly used', err);
98
+ shutdownServers(1);
99
+ })
100
+ .on('unhandledRejection', (reason, p) => {
101
+ console.error('Unhandled Rejection, please checking if await is properly', reason);
102
+ shutdownServers(1);
103
+ });
104
+ function shutdownServers(exitCode) {
93
105
  server.forceShutdown();
94
106
  console.log('RPC server shut down');
95
107
  httpServer.close(function () {
96
108
  console.log('Http server shut down');
97
- process.exit(0);
109
+ process.exit(exitCode);
98
110
  });
99
- });
111
+ }
100
112
  //# sourceMappingURL=processor-runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AAC/F,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC,CAAA;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,iBAAiB,GAAG;IACxB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE;IACrD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE;IAChE,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAA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AAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExC,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzD,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,UAAU,GAAG,IAAI;KACpB,YAAY,CAAC,KAAK,WAAW,GAAG,EAAE,GAAG;IACpC,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,KAAK,UAAU,EAAE;QACrF,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;QAC9C,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACnB;SAAM;QACL,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;KACnB;IACD,GAAG,CAAC,GAAG,EAAE,CAAA;AACX,CAAC,CAAC;KACD,MAAM,CAAC,WAAW,CAAC,CAAA;AAEtB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAA;AAErD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE;IACnB,MAAM,CAAC,aAAa,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;IAEnC,UAAU,CAAC,KAAK,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { compressionAlgorithms } from '@grpc/grpc-js'\n\nimport { register as globalRegistry, Registry } from 'prom-client'\nimport { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'\nimport http from 'http'\n\nconst mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])\n\nimport { ProcessorDefinition } from './gen/processor/protos/processor.js'\nimport { ProcessorServiceImpl } from './service.js'\nimport { Endpoints } from './endpoints.js'\n\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\nimport { setupJsonLogger } from './logger.js'\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n setupJsonLogger()\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n } else {\n const http = chainConfig.Https?.[0]\n if (http) {\n Endpoints.INSTANCE.chainServer.set(id, http)\n } else {\n console.error('not valid config for chain', id)\n }\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n}).use(prometheusServerMiddleware())\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n if (options.debug) {\n console.log('Module loaded', m)\n }\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started at:', options.port)\n\nconst metricsPort = 4040\nconst httpServer = http\n .createServer(async function (req, res) {\n if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {\n const metrics = await mergedRegistry.metrics()\n res.write(metrics)\n } else {\n res.writeHead(404)\n }\n res.end()\n })\n .listen(metricsPort)\n\nconsole.log('Metric Server Started at:', metricsPort)\n\nprocess.on('SIGINT', function () {\n server.forceShutdown()\n console.log('RPC server shut down')\n\n httpServer.close(function () {\n console.log('Http server shut down')\n process.exit(0)\n })\n})\n"]}
1
+ {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,UAAU,CAAA;AAEzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AAC/F,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,SA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AAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAA;AAErD,OAAO;KACJ,EAAE,CAAC,QAAQ,EAAE;IACZ,eAAe,CAAC,CAAC,CAAC,CAAA;AACpB,CAAC,CAAC;KACD,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IAC/B,OAAO,CAAC,KAAK,CAAC,+DAA+D,EAAE,GAAG,CAAC,CAAA;IACnF,eAAe,CAAC,CAAC,CAAC,CAAA;AACpB,CAAC,CAAC;KACD,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,2DAA2D,EAAE,MAAM,CAAC,CAAA;IAClF,eAAe,CAAC,CAAC,CAAC,CAAA;AACpB,CAAC,CAAC,CAAA;AAEJ,SAAS,eAAe,CAAC,QAAgB;IACvC,MAAM,CAAC,aAAa,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;IAEnC,UAAU,CAAC,KAAK,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\n\nimport { compressionAlgorithms } from '@grpc/grpc-js'\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'\nimport { register as globalRegistry, Registry } from 'prom-client'\nimport http from 'http'\n\nimport { ProcessorDefinition } from './gen/processor/protos/processor.js'\nimport { ProcessorServiceImpl } from './service.js'\nimport { Endpoints } from './endpoints.js'\nimport { FullProcessorServiceImpl } from './full-service.js'\nimport { ChainConfig } from './chain-config.js'\nimport { setupJsonLogger } from './logger.js'\n\nconst mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n // { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n setupJsonLogger()\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nEndpoints.INSTANCE.concurrency = options.concurrency\nEndpoints.INSTANCE.chainQueryAPI = options['chainquery-server']\nEndpoints.INSTANCE.priceFeedAPI = options['pricefeed-server']\n\nfor (const [id, config] of Object.entries(chainsConfig)) {\n const chainConfig = config as ChainConfig\n if (chainConfig.ChainServer) {\n Endpoints.INSTANCE.chainServer.set(id, chainConfig.ChainServer)\n } else {\n const http = chainConfig.Https?.[0]\n if (http) {\n Endpoints.INSTANCE.chainServer.set(id, http)\n } else {\n console.error('not valid config for chain', id)\n }\n }\n}\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': compressionAlgorithms.gzip,\n}).use(prometheusServerMiddleware())\n\nconst baseService = new ProcessorServiceImpl(async () => {\n const m = await import(options.target)\n if (options.debug) {\n console.log('Module loaded', m)\n }\n return m\n}, server.shutdown)\nconst service = new FullProcessorServiceImpl(baseService)\n\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started at:', options.port)\n\nconst metricsPort = 4040\nconst httpServer = http\n .createServer(async function (req, res) {\n if (req.url && new URL(req.url, `http://${req.headers.host}`).pathname === '/metrics') {\n const metrics = await mergedRegistry.metrics()\n res.write(metrics)\n } else {\n res.writeHead(404)\n }\n res.end()\n })\n .listen(metricsPort)\n\nconsole.log('Metric Server Started at:', metricsPort)\n\nprocess\n .on('SIGINT', function () {\n shutdownServers(0)\n })\n .on('uncaughtException', (err) => {\n console.error('Uncaught Exception, please checking if await is properly used', err)\n shutdownServers(1)\n })\n .on('unhandledRejection', (reason, p) => {\n console.error('Unhandled Rejection, please checking if await is properly', reason)\n shutdownServers(1)\n })\n\nfunction shutdownServers(exitCode: number) {\n server.forceShutdown()\n console.log('RPC server shut down')\n\n httpServer.close(function () {\n console.log('Http server shut down')\n process.exit(exitCode)\n })\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.18.1-rc.2",
3
+ "version": "2.18.1-rc.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -31,10 +31,10 @@
31
31
  "prom-client": "^14.2.0",
32
32
  "protobufjs": "^7.2.3",
33
33
  "winston": "^3.8.2",
34
- "@sentio/protos": "2.18.1-rc.2"
34
+ "@sentio/protos": "2.18.1-rc.3"
35
35
  },
36
36
  "peerDependencies": {
37
- "@sentio/sdk": "^2.18.1-rc.2"
37
+ "@sentio/sdk": "^2.18.1-rc.3"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/command-line-args": "^5.2.0",
@@ -3,24 +3,22 @@
3
3
  import path from 'path'
4
4
  import fs from 'fs-extra'
5
5
 
6
+ import { compressionAlgorithms } from '@grpc/grpc-js'
6
7
  import commandLineArgs from 'command-line-args'
7
8
  import { createServer } from 'nice-grpc'
8
- import { compressionAlgorithms } from '@grpc/grpc-js'
9
-
10
- import { register as globalRegistry, Registry } from 'prom-client'
11
9
  import { registry as niceGrpcRegistry, prometheusServerMiddleware } from 'nice-grpc-prometheus'
10
+ import { register as globalRegistry, Registry } from 'prom-client'
12
11
  import http from 'http'
13
12
 
14
- const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])
15
-
16
13
  import { ProcessorDefinition } from './gen/processor/protos/processor.js'
17
14
  import { ProcessorServiceImpl } from './service.js'
18
15
  import { Endpoints } from './endpoints.js'
19
-
20
16
  import { FullProcessorServiceImpl } from './full-service.js'
21
17
  import { ChainConfig } from './chain-config.js'
22
18
  import { setupJsonLogger } from './logger.js'
23
19
 
20
+ const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry])
21
+
24
22
  const optionDefinitions = [
25
23
  { name: 'target', type: String, defaultOption: true },
26
24
  { name: 'port', alias: 'p', type: String, defaultValue: '4000' },
@@ -108,12 +106,25 @@ const httpServer = http
108
106
 
109
107
  console.log('Metric Server Started at:', metricsPort)
110
108
 
111
- process.on('SIGINT', function () {
109
+ process
110
+ .on('SIGINT', function () {
111
+ shutdownServers(0)
112
+ })
113
+ .on('uncaughtException', (err) => {
114
+ console.error('Uncaught Exception, please checking if await is properly used', err)
115
+ shutdownServers(1)
116
+ })
117
+ .on('unhandledRejection', (reason, p) => {
118
+ console.error('Unhandled Rejection, please checking if await is properly', reason)
119
+ shutdownServers(1)
120
+ })
121
+
122
+ function shutdownServers(exitCode: number) {
112
123
  server.forceShutdown()
113
124
  console.log('RPC server shut down')
114
125
 
115
126
  httpServer.close(function () {
116
127
  console.log('Http server shut down')
117
- process.exit(0)
128
+ process.exit(exitCode)
118
129
  })
119
- })
130
+ }