Skip to content

Commit

Permalink
Update codegen to add subgraph source to watcher readme (#514)
Browse files Browse the repository at this point in the history
* Update codegen to add subgraph source to watcher readme

* Update exported metrics for watcher config

* Add steps to update package json and config to codegen instructions

---------

Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
  • Loading branch information
nikugogoi and prathamesh0 authored Jun 11, 2024
1 parent acf69dd commit 7884941
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Steps:

This will create a folder containing the generated code at the path provided in config. Follow the steps in [Run Generated Watcher](#run-generated-watcher) to setup and run the generated watcher.

* Update generated watcher's `package.json` with desired `version`, `description`, `repository` URL, etc.
* Update generated watcher's config (`environments/local.toml`) as required

## Development

* `lint`
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/generate-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any, overW
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'README.md'))
: process.stdout;
exportReadme(path.basename(outputDir), config.port, outStream);
exportReadme(path.basename(outputDir), config, outStream);

outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'LICENSE'))
Expand Down
17 changes: 15 additions & 2 deletions packages/codegen/src/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ const TEMPLATE_FILE = './templates/readme-template.handlebars';
* @param port Watcher server port.
* @param outStream A writable output stream to write the README.md file to.
*/
export function exportReadme (folderName: string, port: number, outStream: Writable): void {
export function exportReadme (
folderName: string,
config: { port: number, subgraphPath?: string },
outStream: Writable
): void {
const { port, subgraphPath } = config;
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
let subgraphRepoName;

if (subgraphPath) {
const subgraphRepoDir = path.dirname(subgraphPath);
subgraphRepoName = path.basename(subgraphRepoDir);
}

const readmeString = template({
folderName,
port
port,
subgraphRepoName
});
outStream.write(readmeString);
}
7 changes: 7 additions & 0 deletions packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# {{folderName}}

{{#if (subgraphPath)}}
## Source

<!-- TODO: Update with publised subgraph release version -->
* Subgraph: [{{subgraphRepoName}} v0.1.0](https://github.com/cerc-io/{{subgraphRepoName}}/releases/tag/v0.1.0)

{{/if}}
## Setup

* Run the following command to install required packages:
Expand Down
1 change: 1 addition & 0 deletions packages/util/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const registerWatcherConfigMetrics = async ({ server, upstream, jobQueue }: Conf

watcherConfigMetric.set({ category: 'jobqueue', field: 'num_events_in_batch' }, Number(jobQueue.eventsInBatch));
watcherConfigMetric.set({ category: 'jobqueue', field: 'block_delay_seconds' }, (Number(jobQueue.blockDelayInMilliSecs) || 0) / 1000);
watcherConfigMetric.set({ category: 'jobqueue', field: 'block_processing_offset' }, Number(jobQueue.blockProcessingOffset) ?? 0);
watcherConfigMetric.set({ category: 'jobqueue', field: 'use_block_ranges' }, Number(jobQueue.useBlockRanges));
watcherConfigMetric.set({ category: 'jobqueue', field: 'historical_logs_block_range' }, Number(jobQueue.historicalLogsBlockRange));
watcherConfigMetric.set({ category: 'jobqueue', field: 'historical_max_fetch_ahead' }, Number(jobQueue.historicalMaxFetchAhead));
Expand Down

0 comments on commit 7884941

Please sign in to comment.