-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zabil Cheriya Maliackal <[email protected]>
- Loading branch information
Showing
1 changed file
with
50 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,75 @@ | ||
import gaugeGlobal from "./gauge-global.js"; | ||
import protobuf from "protobufjs"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import protoLoader from "@grpc/proto-loader"; | ||
import path from "path"; | ||
import protobuf from "protobufjs"; | ||
import gaugeGlobal from "./gauge-global.js"; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
import loader from "./static-loader.js"; | ||
const PROTO_PATH = __dirname + "/../gauge-proto/services.proto"; | ||
const PROTO_PATH = `${__dirname}/../gauge-proto/services.proto`; | ||
import grpc from "@grpc/grpc-js"; | ||
|
||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, { | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
oneofs: true, | ||
}); | ||
|
||
const servicesProto = grpc.loadPackageDefinition(packageDefinition).gauge.messages; | ||
const servicesProto = | ||
grpc.loadPackageDefinition(packageDefinition).gauge.messages; | ||
|
||
import ServiceHandlers from "./serviceHandlers.js"; | ||
import logger from "./logger.js"; | ||
import ServiceHandlers from "./serviceHandlers.js"; | ||
|
||
function run() { | ||
global.gauge = gaugeGlobal.gauge; | ||
protobuf.load(path.resolve("gauge-proto/messages.proto")).then(function (root) { | ||
var errorType = root.lookupEnum("gauge.messages.StepValidateResponse.ErrorType"); | ||
var fileStatus = root.lookupEnum("gauge.messages.CacheFileRequest.FileStatus"); | ||
return { errorType: errorType, fileStatus: fileStatus }; | ||
}).catch(function (e) { | ||
logger.error("Failed while loading runner.\n" + e); | ||
process.exit(); | ||
}).then(function (types) { | ||
loader.load(); | ||
var server = new grpc.Server(); | ||
server.addService(servicesProto.Runner.service, new ServiceHandlers(server, types)); | ||
server.bindAsync("127.0.0.1:0", grpc.ServerCredentials.createInsecure(), (err, port) => { | ||
if (!err) { | ||
logger.info("Listening on port:" + port); | ||
server.start(); | ||
} else { | ||
logger.error(err); | ||
process.exit(); | ||
} | ||
protobuf | ||
.load(path.resolve("gauge-proto/messages.proto")) | ||
.then((root) => { | ||
const errorType = root.lookupEnum( | ||
"gauge.messages.StepValidateResponse.ErrorType", | ||
); | ||
const fileStatus = root.lookupEnum( | ||
"gauge.messages.CacheFileRequest.FileStatus", | ||
); | ||
return { errorType: errorType, fileStatus: fileStatus }; | ||
}) | ||
.catch((e) => { | ||
logger.error(`Failed while loading runner.\n${e}`); | ||
process.exit(); | ||
}) | ||
.then((types) => { | ||
loader.load(); | ||
const server = new grpc.Server(); | ||
server.addService( | ||
servicesProto.Runner.service, | ||
new ServiceHandlers(server, types), | ||
); | ||
server.bindAsync( | ||
"127.0.0.1:0", | ||
grpc.ServerCredentials.createInsecure(), | ||
(err, port) => { | ||
if (!err) { | ||
logger.info(`Listening on port:${port}`); | ||
server.start(); | ||
} else { | ||
logger.error(err); | ||
process.exit(); | ||
} | ||
}, | ||
); | ||
}) | ||
.catch((e) => { | ||
logger.error(`${e.message}\n${e.stack}`); | ||
}); | ||
}).catch(function (e) { | ||
logger.error(`${e.message}\n${e.stack}`); | ||
}); | ||
} | ||
|
||
if (process.argv[2] === "--run") { | ||
run(); | ||
} | ||
|
||
export default { | ||
run: run | ||
run: run, | ||
}; |