Skip to content
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
12 changes: 10 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
node_modules/
docs/
coverage/
logs/
*.log
src-old/
bin/
.idea/
.vscode/
.nyc_output/
dist/
*.log
__tests__/
__test__/
docs/
1 change: 0 additions & 1 deletion .envrc

This file was deleted.

6 changes: 4 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
auth.sample.json
auth.json
dist/
*.zip
src-old/
*.md
19 changes: 14 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true,
mocha: true,
es2021: true,
'jest/globals': true,
},
extends: ['airbnb-base', 'plugin:prettier/recommended'],
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:jest/recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
'@typescript-eslint/no-explicit-any': 'off', // TODO: remove rule about no explicit any
'jest/valid-title': 'off',
'no-underscore-dangle': 'off',
'max-len': [
'error',
Expand All @@ -29,3 +37,4 @@ module.exports = {
SharedArrayBuffer: 'readonly',
},
};
;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove the redundant trailing semicolon.

There's an extra semicolon at the end of the file that should be removed.

- };
- ;
+ };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
;
};
🧰 Tools
🪛 ESLint

[error] 40-41: Delete ;⏎

(prettier/prettier)

6 changes: 3 additions & 3 deletions .github/workflows/commit-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Use Node 14.x
- name: Use Node 18.x
uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: '18.x'
Comment on lines +13 to +16

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update GitHub Actions setup-node action to a newer version

The runner for "actions/setup-node@v2" is outdated according to GitHub Actions standards.

Update to a newer version of the action:

-      - name: Use Node 18.x
-        uses: actions/setup-node@v2
+      - name: Use Node 18.x
+        uses: actions/setup-node@v3
        with:
          node-version: '18.x'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Use Node 18.x
uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: '18.x'
- name: Use Node 18.x
uses: actions/setup-node@v3
with:
node-version: '18.x'
🧰 Tools
🪛 actionlint (1.7.4)

14-14: the runner of "actions/setup-node@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

- run: npm ci
- run: npm run test-cov --if-present
- run: npm run test:cov --if-present
- run: npm run lint
- run: npm run pretty-check --if-present
61 changes: 57 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# VSCode
.vscode/

# Project files
*.log
logs/
old-src/

dist/

config/local*.js
8 changes: 8 additions & 0 deletions .mds-log-pumprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"source":"pino",
"pump":"logstashHttp",
"mode":"http",
"host":"localhost",
"port":6002,
"echo":true
}
10 changes: 0 additions & 10 deletions .mocharc.json

This file was deleted.

24 changes: 0 additions & 24 deletions .nycrc.json

This file was deleted.

14 changes: 14 additions & 0 deletions DEV_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@
* Bolt is golang specific, Alternative needed.
* Possible Candidates
* https://github.com/weyoss/redis-smq

## Docker cleanup commands

- Remove dangling images

```
docker rmi $(docker image ls -f dangling=true -q --no-trunc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add safety checks to Docker cleanup commands.

The current commands might fail or produce errors if no matching images are found. Consider adding safety checks.

For the first command:

-docker rmi $(docker image ls -f dangling=true -q --no-trunc)
+docker image ls -f dangling=true -q --no-trunc | xargs -r docker rmi

For the second command:

-docker image ls | grep mds-sf- | awk '{print $3}' | xargs docker rmi
+docker image ls | grep mds-sf- | awk '{print $3}' | xargs -r docker rmi

The -r flag for xargs prevents it from running the command if there are no input arguments.

Also applies to: 47-47

```

- Remove previously built MDS Serverless Functions images

```
docker image ls | grep mds-sf- | awk '{print $3}' | xargs docker rmi
```
35 changes: 31 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
FROM node:10-alpine
FROM node:18 as builder

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

###########################
FROM node:18-alpine

WORKDIR /usr/src/app

COPY package*.json ./
COPY ./config/default.js ./config/default.js
RUN npm install --only=prod

COPY . .
COPY --from=builder /usr/src/app/dist .
# COPY --from=builder /usr/src/app/src/infrastructure/grpc/protos/*.proto ./infrastructure/grpc/protos/
EXPOSE 8888

ENTRYPOINT [ "node", "./bin/entrypoint" ]
CMD [ "server" ]
# NOTE: the mds state machine is broken up into two components. The first is the
# API server which is the presentation/server.js file. The second is the worker
# which is the /worker/entry-point.js file.
CMD [ "node", "./presentation/server.js" ]

# To ship logs to the ELK stack extend the above command
# with either pino-socket, pino-logstash or mds-log-pump.
# An example using mds-log-pump can be found in the mds
# stack configurations. This utilizes a simple config file
# and allows a out-of-process to handle shipping logs to
# the ELK stack.
#
# If you chose to use pino-socket or pino-logstash you will
# need to refer to their documentation for configuration.
#
# Ex: CMD [ "node", "./server.js", "|", "mds-log-pump"]
# Ex: CMD [ "node", "./server.js", "|", "pino-logstash", "-h", "elk", "-p", "5000" ]
# Ex: CMD [ "node", "./server.js", "|", "pino-socket", "-h", "elk", "-p", "5000" ]
36 changes: 0 additions & 36 deletions Jenkinsfile

This file was deleted.

12 changes: 12 additions & 0 deletions __mocks__/@maddonkeysoftware/mds-cloud-sdk-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { mockFunctionsClient, mockQueueClient } from '../../src/test-utilities';

module.exports = {
MdsSdk: {
getQueueServiceClient: jest
.fn()
.mockReturnValue(Promise.resolve(mockQueueClient)),
getServerlessFunctionsClient: jest
.fn()
.mockReturnValue(Promise.resolve(mockFunctionsClient)),
},
};
29 changes: 24 additions & 5 deletions bin/entrypoint
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
#!/usr/bin/env node
const mdsSdk = require('@maddonkeysoftware/mds-cloud-sdk-node');

const src = require('../src');
const globals = require('../src/globals');
const worker = require('../src/workers');
const appShutdown = require('../src/handlers/app_shutdown');
const src = require('../src-old');
const globals = require('../src-old/globals');
const worker = require('../src-old/workers');
const appShutdown = require('../src-old/handlers/app_shutdown');

const directive = process.argv[2];
const logger = globals.getLogger();

const ensureSystemQueuesExist = async () => {
// mds qs create --env localAdmin mds-sm-inFlightQueue && mds qs create --env localAdmin mds-sm-pendingQueue
const queueNames = ['mds-sm-inFlightQueue', 'mds-sm-pendingQueue'];
const client = await mdsSdk.getQueueServiceClient()
const existingQueues = await client.listQueues();

for (const queueName of queueNames) {
const queueExists = existingQueues.some((q) => q.name === queueName);
if (!queueExists) {
logger.info(`Creating queue ${queueName}`);
await client.createQueue(queueName);
}
}
};

const launchServer = async () => {
await mdsSdk.initialize({
identityUrl: process.env.MDS_IDENTITY_URL,
Expand All @@ -18,7 +33,9 @@ const launchServer = async () => {
sfUrl: process.env.MDS_SM_SF_URL,
qsUrl: process.env.MDS_SM_QS_URL,
});
appShutdown.wire();
appShutdown.wire(() => process.exit(0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider more graceful shutdown approach

Using process.exit(0) prevents graceful shutdown of connections or pending operations, which could lead to resource leaks or incomplete operations.

-  appShutdown.wire(() => process.exit(0));
+  appShutdown.wire(async () => {
+    logger.info('Server shutdown initiated');
+    // Wait for connections to drain or timeout
+    try {
+      // Close any active connections
+      await app.close();
+      logger.info('Server shutdown complete');
+      process.exit(0);
+    } catch (err) {
+      logger.error({ err }, 'Error shutting down server');
+      process.exit(1);
+    }
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
appShutdown.wire(() => process.exit(0));
appShutdown.wire(async () => {
logger.info('Server shutdown initiated');
// Wait for connections to drain or timeout
try {
// Close any active connections
await app.close();
logger.info('Server shutdown complete');
process.exit(0);
} catch (err) {
logger.error({ err }, 'Error shutting down server');
process.exit(1);
}
});


await ensureSystemQueuesExist();

const port = process.env.APP_PORT || 8888;
const app = src.buildApp();
Expand All @@ -37,6 +54,8 @@ const launchWorker = async () => {
});
appShutdown.wire(worker.handleAppShutdown);

await ensureSystemQueuesExist();

worker.startWorker();
};

Expand Down
Loading