mirror of https://github.com/embarklabs/embark.git
Rebase updates
After the code was rebased, there were some additional changes for getting websockets logs that needed to be catered for. When there is a call to get all logs for a process, the state entity is updated with a new array item containing all the logs (this is then reduced and selected for rendering). In the case of a websocket log that simply returns only one log item, the latest full log for the process is found in the state entities, and it’s logs are appending to with the data from the websocket. Additionally, log limits were updated to be passed in as a parameter to the API calls from the frontend. Parameter validation (for `limit`) was also added in this commit.
This commit is contained in:
parent
d4d7e3b8ac
commit
46511bcfe8
|
@ -99,11 +99,12 @@ export const commands = {
|
|||
|
||||
export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS');
|
||||
export const processLogs = {
|
||||
request: (processName) => action(PROCESS_LOGS[REQUEST], {processName}),
|
||||
request: (processName, limit) => action(PROCESS_LOGS[REQUEST], {processName, limit}),
|
||||
success: (processLogs, payload) => {
|
||||
return action(PROCESS_LOGS[SUCCESS],
|
||||
{
|
||||
processLogs: [
|
||||
{
|
||||
ws: !!payload.ws,
|
||||
processLogs: [
|
||||
{
|
||||
process: payload.processName,
|
||||
timestamp: new Date().getTime(),
|
||||
|
|
|
@ -46,7 +46,7 @@ class Console extends Component {
|
|||
renderCommandsResult(){
|
||||
const {commands} = this.props;
|
||||
return (
|
||||
this.state.selectedProcess === DEFAULT_PROCESS &&
|
||||
this.props.isEmbark() &&
|
||||
commands.map((command, index) => {
|
||||
return <CommandResult key={index} result={command.result}/>;
|
||||
})
|
||||
|
@ -57,8 +57,8 @@ class Console extends Component {
|
|||
const {processes} = this.props;
|
||||
return processes
|
||||
.sort((a, b) => { // ensure the "Embark" tab is displayed first
|
||||
if (a.name === DEFAULT_PROCESS) return -1;
|
||||
if (b.name === DEFAULT_PROCESS) return 1;
|
||||
if (a.name === 'embark') return -1;
|
||||
if (b.name === 'embark') return 1;
|
||||
return 0;
|
||||
})
|
||||
.map(process => (
|
||||
|
|
|
@ -9,7 +9,8 @@ import Processes from '../components/Processes';
|
|||
import Console from '../components/Console';
|
||||
import {getProcesses, getCommands, getProcessLogs} from "../reducers/selectors";
|
||||
|
||||
const EMBARK_PROCESS_NAME = 'Embark';
|
||||
const EMBARK_PROCESS_NAME = 'embark';
|
||||
const LOG_LIMIT = 50;
|
||||
|
||||
class HomeContainer extends Component {
|
||||
constructor(props) {
|
||||
|
@ -30,8 +31,8 @@ class HomeContainer extends Component {
|
|||
this.props.stopProcessLogs(this.state.activeProcess)
|
||||
}
|
||||
|
||||
this.props.fetchProcessLogs(processName, LOG_LIMIT);
|
||||
if (processName !== EMBARK_PROCESS_NAME) {
|
||||
this.props.fetchProcessLogs(processName);
|
||||
this.props.listenToProcessLogs(processName);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {combineReducers} from 'redux';
|
||||
import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE,
|
||||
FETCH_CREDENTIALS, UPDATE_BASE_ETHER} from "../actions";
|
||||
FETCH_CREDENTIALS, UPDATE_BASE_ETHER, PROCESS_LOGS} from "../actions";
|
||||
|
||||
const BN_FACTOR = 10000;
|
||||
const VOID_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
@ -103,6 +103,12 @@ const filtrer = {
|
|||
};
|
||||
|
||||
function entities(state = entitiesDefaultState, action) {
|
||||
if (action.type === PROCESS_LOGS[SUCCESS] && action.ws === true){
|
||||
const process = action.processLogs[0].process;
|
||||
let processLogs = state.processLogs.filter(logs => logs.process === process).sort((a, b) => b.timestamp - a.timestamp)[0];
|
||||
processLogs.logs.push(action.processLogs[0].logs[0]);
|
||||
return {...state};
|
||||
}
|
||||
if (action.type === FILES[SUCCESS]) {
|
||||
return {...state, files: action.files};
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ export function *listenToProcessLogs(action) {
|
|||
return;
|
||||
}
|
||||
|
||||
yield put(actions.processLogs.success([processLog]));
|
||||
yield put(actions.processLogs.success([processLog], {processName: action.processName, ws: true}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ export function fetchProcesses() {
|
|||
}
|
||||
|
||||
export function fetchProcessLogs(payload) {
|
||||
return get(`/process-logs/${payload.processName}`, ...arguments);
|
||||
return get(`/process-logs/${payload.processName}`, {params: payload, processName: payload.processName, credentials: payload.credentials});
|
||||
}
|
||||
|
||||
export function fetchContractLogs() {
|
||||
|
|
|
@ -55,7 +55,7 @@ class Logger {
|
|||
}
|
||||
|
||||
// if 'limit' is specified, get log lines from the end of the log file
|
||||
if(limit && logs.length > limit){
|
||||
if(limit && limit > 0 && logs.length > limit){
|
||||
logs.slice(limit * -1);
|
||||
}
|
||||
return logs;
|
||||
|
|
|
@ -11,7 +11,9 @@ class LoggerApi {
|
|||
'get',
|
||||
'/embark-api/process-logs/embark',
|
||||
(req, res) => {
|
||||
res.send(this.logger.parseLogFile(req.query.limit));
|
||||
let limit = parseInt(req.query.limit, 10);
|
||||
if(!Number.isInteger(limit)) limit = 0;
|
||||
res.send(this.logger.parseLogFile(limit));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue