Skip to content

Commit

Permalink
Removed useless run options
Browse files Browse the repository at this point in the history
  • Loading branch information
chamorin committed Jun 7, 2023
1 parent e7db49b commit cffc6bd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 119 deletions.
106 changes: 40 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,89 +35,63 @@ npm install substreams-sink
### CLI

```bash
Usage: substreams-sink run [options] [<manifest>] <module_name>
Usage: substreams-sink run [options]

Substreams Sink CLI

Arguments:
<manifest> URL or IPFS hash of Substreams package
module_name Name of the output module (declared in the manifest)
Substreams sink CLI module

Options:
-e --substreams-endpoint <string> Substreams gRPC endpoint to stream data from (default:
"https://mainnet.eth.streamingfast.io:443")
-s --start-block <int> Start block to stream from (defaults to -1, which means
the initialBlock of the first module you are streaming)
-t --stop-block <string> Stop block to end stream at, inclusively
-e --substreams-endpoint <string> Substreams gRPC endpoint to stream data from
--manifest <string> URL of Substreams package
--module-name <string> Name of the output module (declared in the manifest)
-p, --params <string...> Set a params for parameterizable modules. Can be specified multiple times. (ex: -p module1=valA -p module2=valX&valY) (default: [])
-s --start-block <int> Start block to stream from (defaults to -1, which means the initialBlock of the first module you are streaming)
-t --stop-block <int> Stop block to end stream at, inclusively
--substreams-api-token <string> API token for the substream endpoint
--substreams-api-token-envvar <string> Environnement variable name of the API token for the
substream endpoint (default: "SUBSTREAMS_API_TOKEN")
--delay-before-start <int> [OPERATOR] Amount of time in milliseconds (ms) to wait
before starting any internal processes, can be used to
perform to maintenance on the pod before actually
letting it starts (default: "0")
--substreams-api-token-envvar <string> Environnement variable name of the API token for the substream endpoint (default: "SUBSTREAMS_API_TOKEN")
--delay-before-start <int> [OPERATOR] Amount of time in milliseconds (ms) to wait before starting any internal processes, can be used to perform to maintenance on the pod before actually
letting it starts
--cursor-file <string> cursor lock file (default: "cursor.lock")
--production-mode Enable Production Mode, with high-speed parallel
processing (default: false)
--production-mode Enable Production Mode, with high-speed parallel processing (default: false)
--verbose Enable verbose logging (default: false)
--metrics-listen-address <string> The process will listen on this address for Prometheus
metrics requests (default: "localhost")
--metrics-listen-port <int> The process will listen on this port for Prometheus
metrics requests (default: "9102")
--metrics-disabled If set, will not send metrics to Prometheus (default:
false)
-p, --params <string...> Set a params for parameterizable modules. Can be
specified multiple times. Ex: -p module1=valA -p
module2=valX&valY (default: [])
--metrics-listen-address <string> The process will listen on this address for Prometheus metrics requests (default: "localhost")
--metrics-listen-port <int> The process will listen on this port for Prometheus metrics requests (default: "9102")
--metrics-disabled If set, will not send metrics to Prometheus (default: false)
-h, --help display help for command
```

### Example

```js
import { download, createHash } from "substreams";
import { cli, run, logger, RunOptions } from "substreams-sink";
import { fetchSubstream } from "@substreams/core";
import { run, logger, cli } from "substreams-sink";

const pkg = {
name: 'substreams-sink-rabbitmq',
version: '0.1.0',
description: 'Substreams data to RabbitMQ',
}
logger.defaultMeta = { service: pkg.name };
import pkg from "./package.json" assert { type: "json" };

const program = cli.program(pkg);
const command = cli.run(program, pkg);
command.option('-U --username <string>', 'RabbitMQ username.', 'guest');
command.option('-P --password <string>', 'RabbitMQ password.', 'guest');
command.option('-p --port <int>', 'Listens on port number.', '5672');
command.option('-a --address <string>', 'RabbitMQ address to connect.', 'localhost');
command.action(action);
program.parse();

interface ActionOptions extends RunOptions {
address: string;
port: number;
username: string;
password: string;
const command = cli.option(program, pkg);

logger.setName(pkg.name);
export { logger };

// Custom user options interface
interface ActionOptions extends cli.RunOptions {
customOption: any
// ...
}

async function action(manifest: string, moduleName: string, options: ActionOptions) {
// Download Substreams (or read from local file system)
const spkg = await download(manifest);
const hash = createHash(spkg);
logger.info("download", {manifest, hash});

// Handle custom Sink Options
const { address, port, username, password } = options;
const rabbitmq = `amqp://${username}:${password}@${address}:${port}`;
logger.info("connect", {rabbitmq});

// Run Substreams
const substreams = run(spkg, moduleName, options);
substreams.on("anyMessage", message => {
// Handle message
logger.info("anyMessage", message);
})
export async function action(options: ActionOptions) {
const spkg = await fetchSubstream(options.manifest!);

// Get command options
const { customOption } = options;

// Run substreams
const substreams = run(spkg, options);

substreams.on("anyMessage", async (messages: any) => {
// Sink logic here
});

substreams.start(options.delayBeforeStart);
}
```
46 changes: 0 additions & 46 deletions example.ts

This file was deleted.

12 changes: 5 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { Command } from "commander";

export interface RunOptions {
substreamsEndpoint: string;
manifest: string;
moduleName: string;
params: string[];
startBlock?: string;
stopBlock?: string;
substreamsEndpoint: string;
manifest?: string;
spkg?: string;
substreamsApiTokenEnvvar: string;
substreamsApiToken?: string;
substreamsApiTokenEnvvar: string;
delayBeforeStart?: number;
cursorFile: string;
productionMode: boolean;
verbose: boolean;
metricsListenAddress: string;
metricsListenPort: number;
metricsDisabled: boolean;
chain?: string;
params: string[];
moduleName?: string;
}

// default substreams options
Expand Down
1 change: 1 addition & 0 deletions src/prometheus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import client, { Counter, Gauge } from "prom-client";
import http from "node:http";
import type { BlockScopedData, Clock } from "@substreams/core/proto";

import { logger } from "./logger.js";

// Prometheus Exporter
Expand Down

0 comments on commit cffc6bd

Please sign in to comment.