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

fix: export logs error #567

Merged
merged 2 commits into from
Jan 2, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
## Unreleased

- Fixed sorting symbols open trades first by [@uhliksk](https://github.com/uhliksk) - [#564](https://github.com/chrisleekr/binance-trading-bot/pull/564)
- Fixed the issue that cannot export huge logs - [#561](https://github.com/chrisleekr/binance-trading-bot/pull/561)
- Fixed the issue that cannot export huge logs - [#561](https://github.com/chrisleekr/binance-trading-bot/pull/561), [#567](https://github.com/chrisleekr/binance-trading-bot/pull/567)

Thanks [@uhliksk](https://github.com/uhliksk) for your great contributions. 💯 :heart:

Expand Down
3 changes: 3 additions & 0 deletions app/__tests__/server-frontend.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable global-require */
const path = require('path');

describe('server-frontend', () => {
let mockExpressStatic;
Expand Down Expand Up @@ -36,6 +37,8 @@ describe('server-frontend', () => {

let reqPath;

global.appRoot = path.join(__dirname, '/../');

beforeEach(() => {
jest.clearAllMocks().resetModules();
reqPath = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('webserver/handlers/grid-trade-logs-export', () => {
let postReq;

let mockVerifyAuthenticated;
global.appRoot = path.join(__dirname, '/../../../../');

beforeEach(async () => {
jest.clearAllMocks().resetModules();
Expand Down
16 changes: 8 additions & 8 deletions app/frontend/webserver/handlers/grid-trade-logs-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const handleGridTradeLogsExport = async (funcLogger, app) => {
});
}

const fileName = `${symbol}-${moment().format('YYYY-MM-DD-HH-MM-ss')}.json`;
const fileFolder = path.join(global.appRoot, '/../public/data/logs');

if (!fs.existsSync(fileFolder)) {
fs.mkdirSync(fileFolder);
}
keepLastLogs(fileFolder, 10);

const match = {};
const group = {};

Expand All @@ -63,14 +71,6 @@ const handleGridTradeLogsExport = async (funcLogger, app) => {
const rows = await mongo.findAll(logger, 'trailing-trade-logs', match, {
sort: { loggedAt: -1 }
});
const fileName = `${symbol}-${moment().format('YYYY-MM-DD-HH-MM-ss')}.json`;
const fileFolder = path.join(__dirname, '/../../../../public/data/logs');

if (!fs.existsSync(fileFolder)) {
fs.mkdirSync(fileFolder);
}

keepLastLogs(fileFolder, 10);

const filePath = `${fileFolder}${directorySeparator}${fileName}`;
fs.writeFileSync(filePath, JSON.stringify(rows));
Expand Down
2 changes: 1 addition & 1 deletion app/server-frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const runFrontend = async serverLogger => {
next();
};
app.use(attachmentMiddleware);
app.use(express.static(path.join(__dirname, '/../public')));
app.use(express.static(path.join(global.appRoot, '/../public')));

// Must configure bull board before listen.
configureBullBoard(app, logger);
Expand Down
3 changes: 3 additions & 0 deletions app/server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const path = require('path');
const { logger: rootLogger, mongo } = require('./helpers');
const { runBinance } = require('./server-binance');
const { runCronjob } = require('./server-cronjob');
const { runFrontend } = require('./server-frontend');
const { runErrorHandler } = require('./error-handler');

global.appRoot = path.resolve(__dirname);

(async () => {
const logger = rootLogger.child({
gitHash: process.env.GIT_HASH || 'unspecified'
Expand Down