-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from pheuberger/cronjob-safe-queue
Run cron job to start Safe signature requests queue processing
- Loading branch information
Showing
6 changed files
with
84 additions
and
33 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import cron from "node-cron"; | ||
|
||
import SignatureRequestProcessor from "../services/SignatureRequestProcessor.js"; | ||
|
||
export default class SignatureRequestProcessorCron { | ||
private static instance: SignatureRequestProcessorCron; | ||
private processor: SignatureRequestProcessor; | ||
|
||
private constructor() { | ||
this.processor = SignatureRequestProcessor.getInstance(); | ||
this.setupCronJob(); | ||
} | ||
|
||
private setupCronJob() { | ||
// Run every 30 seconds | ||
cron.schedule("*/30 * * * * *", async () => { | ||
try { | ||
await this.processor.processPendingRequests(); | ||
} catch (error) { | ||
console.error("Error in signature request processor cron job:", error); | ||
} | ||
}); | ||
} | ||
|
||
public static start(): void { | ||
if (!SignatureRequestProcessorCron.instance) { | ||
SignatureRequestProcessorCron.instance = | ||
new SignatureRequestProcessorCron(); | ||
} | ||
} | ||
} |
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,63 +1,61 @@ | ||
import './instrument.js'; | ||
import express, {type Express} from "express"; | ||
import "./instrument.js"; | ||
import express, { type Express } from "express"; | ||
import "reflect-metadata"; | ||
import cors from "cors"; | ||
import {assertExists} from "./utils/assertExists.js"; | ||
import {yoga} from "./client/graphql.js"; | ||
import { assertExists } from "./utils/assertExists.js"; | ||
import { yoga } from "./client/graphql.js"; | ||
import swaggerUi from "swagger-ui-express"; | ||
import swaggerJson from "./__generated__/swagger.json" assert {type: "json"} | ||
import {RegisterRoutes} from "./__generated__/routes/routes.js"; | ||
import * as Sentry from '@sentry/node'; | ||
import swaggerJson from "./__generated__/swagger.json" assert { type: "json" }; | ||
import { RegisterRoutes } from "./__generated__/routes/routes.js"; | ||
import * as Sentry from "@sentry/node"; | ||
import SignatureRequestProcessorCron from "./cron/SignatureRequestProcessing.js"; | ||
|
||
// @ts-expect-error BigInt is not supported by JSON | ||
BigInt.prototype.toJSON = function () { | ||
const int = Number.parseInt(this.toString()); | ||
return int ?? this.toString(); | ||
const int = Number.parseInt(this.toString()); | ||
return int ?? this.toString(); | ||
}; | ||
|
||
// @ts-expect-error BigInt is not supported by JSON | ||
BigInt.prototype.fromJSON = function () { | ||
return BigInt(this.toString()); | ||
return BigInt(this.toString()); | ||
}; | ||
|
||
const PORT = assertExists(process.env.PORT, "PORT"); | ||
|
||
const app: Express = express(); | ||
|
||
app.use(express.urlencoded({extended: true, limit: '1mb'})); | ||
app.use(express.json({limit: '1mb'})); | ||
app.use(express.urlencoded({ extended: true, limit: "1mb" })); | ||
app.use(express.json({ limit: "1mb" })); | ||
app.use(cors()); | ||
|
||
app.get('/health', (req, res) => { | ||
const data = { | ||
uptime: process.uptime(), | ||
message: 'OK', | ||
date: new Date() | ||
} | ||
app.get("/health", (req, res) => { | ||
const data = { | ||
uptime: process.uptime(), | ||
message: "OK", | ||
date: new Date(), | ||
}; | ||
|
||
res.status(200).send(data); | ||
res.status(200).send(data); | ||
}); | ||
|
||
// Bind GraphQL Yoga to the graphql endpoint to avoid rendering the playground on any path | ||
app.use(yoga.graphqlEndpoint, yoga); | ||
|
||
app.use( | ||
"/spec", | ||
swaggerUi.serve, | ||
swaggerUi.setup(swaggerJson) | ||
); | ||
app.use("/spec", swaggerUi.serve, swaggerUi.setup(swaggerJson)); | ||
|
||
RegisterRoutes(app); | ||
|
||
// The error handler must be registered before any other error middleware and after all controllers | ||
Sentry.setupExpressErrorHandler(app); | ||
|
||
app.listen(PORT, () => { | ||
console.log( | ||
`🕸️ Running a GraphQL API server at http://localhost:${PORT}/v1/graphql` | ||
); | ||
// Start Safe signature request processing cron job | ||
SignatureRequestProcessorCron.start(); | ||
|
||
console.log(`🚀 Running Swagger docs at http://localhost:${PORT}/spec`); | ||
app.listen(PORT, () => { | ||
console.log( | ||
`🕸️ Running a GraphQL API server at http://localhost:${PORT}/v1/graphql`, | ||
); | ||
|
||
console.log(`🚀 Running Swagger docs at http://localhost:${PORT}/spec`); | ||
}); | ||
|
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