-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use express and add UI status page for the relayer jobs (#41)
- Loading branch information
Showing
10 changed files
with
94 additions
and
75 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
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
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Bull from "bull"; | ||
|
||
export abstract class BaseProcessor { | ||
queue: Bull.Queue; | ||
constructor(name: string) { | ||
this.queue = new Bull(name); | ||
} | ||
|
||
/** | ||
* Initialise the processor, but this method won't trigger the event processing | ||
* @returns The processor | ||
*/ | ||
abstract init(): this; | ||
|
||
/** | ||
* Reset everything(cache) if processor is already running, otherwise start the event processing. | ||
* @returns Promise<void> | ||
*/ | ||
abstract reset(): Promise<void>; | ||
|
||
getQueue() { | ||
return this.queue; | ||
} | ||
|
||
async clean(): Promise<void> { | ||
await this.queue.obliterate({ force: true }); | ||
} | ||
} |
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
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
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
This file was deleted.
Oops, something went wrong.
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
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,25 +1,34 @@ | ||
import Koa from "koa"; | ||
import bodyParser from "koa-bodyparser"; | ||
import cors from "@koa/cors"; | ||
import bunyan from "bunyan"; | ||
import express from "express"; | ||
import cors from "cors"; | ||
import bodyParser from "body-parser"; | ||
import { ExpressAdapter } from '@bull-board/express'; | ||
|
||
import { config } from "./config"; | ||
import { Processors } from "./processors"; | ||
// import { sync } from "./service/zero"; | ||
|
||
const app = new Koa(); | ||
const app = express(); | ||
|
||
// Enable cors with default options | ||
app.use(cors()); | ||
const logger = bunyan.createLogger({ name: "xdc-relayer" }); | ||
|
||
const processors = new Processors(logger); | ||
|
||
// Enable bodyParser with default options | ||
app.use(bodyParser()); | ||
// Body Parser Middleware | ||
// To parse URL-encoded data | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
// To parse json data | ||
app.use(bodyParser.json()); | ||
|
||
const serverAdapter = new ExpressAdapter(); | ||
serverAdapter.setBasePath('/status'); | ||
|
||
// "/status" route show the relayer job status | ||
app.use('/status', serverAdapter.getRouter()); | ||
|
||
app.listen(config.port, async () => { | ||
logger.info(`Relayer running on port ${config.port}`); | ||
await processors.init().reset(); | ||
logger.info(`Relayer running on port ${config.port}, check its status at "/stats"`); | ||
await processors.init(serverAdapter).reset(); | ||
}); | ||
|