Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge staging to main to update production server #134

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- Production - [![CI/CD](https://github.com/Giveth/impact-graph/actions/workflows/master-pipeline.yml/badge.svg)](https://github.com/Giveth/impact-graph/actions/workflows/master-pipeline.yml)

---

ImpactQL is a GraphQL server, that enables rapid development of serverless impact project applications. It does this by taking care of the persistance of impact project data.

[Installation](#installation)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"test:bootstrap": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/server/bootstrap.test.ts",
"test:utils": "NODE_ENV=test mocha ./src/utils/utils.test.ts",
"test:inverterScript": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/scripts/syncDataWithInverter.test.ts",
"test:healthCheck": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/server/bootstrap.test.ts",
"start": "NODE_ENV=development ts-node-dev --project ./tsconfig.json --respawn ./src/index.ts",
"start:test": "NODE_ENV=development ts-node-dev --project ./tsconfig.json --respawn ./test.ts",
"serve": "pm2 startOrRestart ecosystem.config.js --node-args='--max-old-space-size=8192'",
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@ class Config {

const config = new Config(process.env);

export const isGraphQlMode = config.get('GRAPHQL_MODE') === 'true';
export const isJobMode = config.get('JOB_MODE') === 'true';

export default config;
3 changes: 2 additions & 1 deletion src/orm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataSource } from 'typeorm';
import { PostgresConnectionCredentialsOptions } from 'typeorm/driver/postgres/PostgresConnectionCredentialsOptions';
import config from './config';
import config, { isJobMode } from './config';
import { CronJob } from './entities/CronJob';
import { getEntities } from './entities/entities';
import { redisConfig } from './redis';
Expand Down Expand Up @@ -57,6 +57,7 @@ export class AppDataSource {
},
},
poolSize,
migrationsRun: isJobMode,
extra: {
maxWaitingClients: 10,
evictionRunIntervalMillis: 500,
Expand Down
2 changes: 1 addition & 1 deletion src/server/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ describe('health check test case', healthCheckTestCases);
function healthCheckTestCases() {
it('should return empty array for now startTimestamp', async () => {
const result = await axios.get('http://localhost:4000/health');
assert.equal(result.data, 'Hi every thing seems ok');
assert.equal(result.data, 'OK');
});
}
21 changes: 13 additions & 8 deletions src/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginSchemaReporting } from '@apollo/server/plugin/schemaReporting';
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
import express, { json, Request } from 'express';
import express, { json, Request, RequestHandler } from 'express';
import { Container } from 'typedi';
import { Resource } from '@adminjs/typeorm';
import { validate } from 'class-validator';
Expand All @@ -18,7 +18,7 @@ import bodyParser from 'body-parser';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
import { ApolloServerErrorCode } from '@apollo/server/errors';
import config from '../config';
import config, { isGraphQlMode, isJobMode } from '../config';
import { handleStripeWebhook } from '../utils/stripe';
import createSchema from './createSchema';
import SentryLogger from '../sentryLogger';
Expand Down Expand Up @@ -83,9 +83,6 @@ export async function bootstrap() {
try {
logger.debug('bootstrap() has been called', new Date());

const isGraphQlMode = config.get('GRAPHQL_MODE') === 'true';
const isJobMode = config.get('JOB_MODE') === 'true';

logger.info('isGraphQlMode: ', isGraphQlMode);
logger.info('isJobMode: ', isJobMode);

Expand Down Expand Up @@ -424,9 +421,7 @@ export async function bootstrap() {
bodyParser.raw({ type: 'application/json' }),
handleStripeWebhook,
);
app.get('/health', (_req, res) => {
res.send('Hi every thing seems ok');
});
app.get('/health', healthCheck);
app.post('/transak_webhook', webhookHandler);

const httpServer = http.createServer(app);
Expand Down Expand Up @@ -472,3 +467,13 @@ async function setPgTrgmParameters(ds: DataSource) {
`SET pg_trgm.word_similarity_threshold TO ${similarityThreshold};`,
);
}

const healthCheck: RequestHandler = async (_req, res) => {
const ds = AppDataSource.getDataSource();
const result = (await ds.query('select version()')) || [];
const version = result[0]?.version || '';
if (!version.startsWith('PostgreSQL')) {
throw new Error('Unexpected db result');
}
res.sendStatus(200);
};
Loading