Gracefully shutdown server (#265)

* Gracefully shutdown server

* Forbid lint warnings

* Avoid setting subgraph path in template contex in codegen
This commit is contained in:
prathamesh0
2022-11-28 12:01:28 +05:30
committed by GitHub
parent 2417e3feb1
commit bd8f003322
19 changed files with 57 additions and 48 deletions
+1 -3
View File
@@ -71,9 +71,7 @@ export class Client {
this._exportGql(schemaContent, gqlDir);
const template = Handlebars.compile(this._templateString);
const client = template({
queries: this._queries
});
const client = template({ queries: this._queries });
outStream.write(client);
}
+2 -3
View File
@@ -16,14 +16,13 @@ const TEMPLATE_FILE = './templates/config-template.handlebars';
* @param folderName Watcher folder name to be passed to the template.
* @param outStream A writable output stream to write the config file to.
*/
export function exportConfig (watcherKind: string, port: number, folderName: string, outStream: Writable, subgraphPath?: string): void {
export function exportConfig (watcherKind: string, port: number, folderName: string, outStream: Writable): void {
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const config = template({
watcherKind,
port,
folderName,
subgraphPath
folderName
});
outStream.write(config);
}
+2 -2
View File
@@ -13,9 +13,9 @@ const FILL_TEMPLATE_FILE = './templates/fill-template.handlebars';
* Writes the fill file generated from a template to a stream.
* @param fillOutStream A writable output stream to write the fill file to.
*/
export function exportFill (fillOutStream: Writable, subgraphPath: string): void {
export function exportFill (fillOutStream: Writable): void {
const templateString = fs.readFileSync(path.resolve(__dirname, FILL_TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const fill = template({ subgraphPath });
const fill = template({});
fillOutStream.write(fill);
}
+4 -4
View File
@@ -193,12 +193,12 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/server.ts'))
: process.stdout;
exportServer(outStream, config.subgraphPath);
exportServer(outStream);
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'environments/local.toml'))
: process.stdout;
exportConfig(config.kind, config.port, path.basename(outputDir), outStream, config.subgraphPath);
exportConfig(config.kind, config.port, path.basename(outputDir), outStream);
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/database.ts'))
@@ -228,7 +228,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/job-runner.ts'))
: process.stdout;
exportJobRunner(outStream, config.subgraphPath);
exportJobRunner(outStream);
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/cli/watch-contract.ts'))
@@ -268,7 +268,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
const fillOutStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/fill.ts'))
: process.stdout;
exportFill(fillOutStream, config.subgraphPath);
exportFill(fillOutStream);
outStream = outputDir
? fs.createWriteStream(path.join(outputDir, 'src/types.ts'))
+2 -2
View File
@@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/job-runner-template.handlebars';
* Writes the job-runner file generated from a template to a stream.
* @param outStream A writable output stream to write the events file to.
*/
export function exportJobRunner (outStream: Writable, subgraphPath: string): void {
export function exportJobRunner (outStream: Writable): void {
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const events = template({ subgraphPath });
const events = template({});
outStream.write(events);
}
+1 -3
View File
@@ -17,8 +17,6 @@ const TEMPLATE_FILE = './templates/package-template.handlebars';
export function exportPackage (folderName: string, outStream: Writable): void {
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const packageString = template({
folderName
});
const packageString = template({ folderName });
outStream.write(packageString);
}
+2 -2
View File
@@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/server-template.handlebars';
* Writes the server file generated from a template to a stream.
* @param outStream A writable output stream to write the server file to.
*/
export function exportServer (outStream: Writable, subgraphPath: string): void {
export function exportServer (outStream: Writable): void {
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
const template = Handlebars.compile(templateString);
const server = template({ subgraphPath });
const server = template({});
outStream.write(server);
}
@@ -9,8 +9,8 @@
"build": "yarn clean && tsc && yarn copy-assets",
"clean": "rm -rf ./dist",
"copy-assets": "copyfiles -u 1 src/**/*.gql dist/",
"server": "DEBUG=vulcanize:* node --enable-source-maps dist/server.js",
"server:dev": "DEBUG=vulcanize:* ts-node src/server.ts",
"server": "DEBUG=vulcanize:* YARN_CHILD_PROCESS=true node --enable-source-maps dist/server.js",
"server:dev": "DEBUG=vulcanize:* YARN_CHILD_PROCESS=true ts-node src/server.ts",
"job-runner": "DEBUG=vulcanize:* YARN_CHILD_PROCESS=true node --enable-source-maps dist/job-runner.js",
"job-runner:dev": "DEBUG=vulcanize:* YARN_CHILD_PROCESS=true ts-node src/job-runner.ts",
"watch:contract": "DEBUG=vulcanize:* ts-node src/cli/watch-contract.ts",
@@ -45,8 +45,3 @@ main().then(() => {
}).catch(err => {
log(err);
});
process.on('SIGINT', () => {
log(`Exiting process ${process.pid} with code 0`);
process.exit(0);
});