Skip to content

Commit

Permalink
fix: add back support for agent-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Silberman committed Jul 17, 2019
1 parent 5cfa8c4 commit d980055
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/@best/agent-logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import chalk from 'chalk';
export { loggedSocket } from './socket';
export { loggedSocket, LoggedSocket } from './socket';

const THROTTLE_WAIT = 750;

Expand Down
2 changes: 1 addition & 1 deletion packages/@best/agent-logger/src/socket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AgentLogger from './index';
import { sanitize } from './utils/sanitize';

interface LoggedSocket {
export interface LoggedSocket {
rawSocket: SocketIO.Socket;
on(event: string, listener: (...args: any[]) => void): void;
once(event: string, listener: (...args: any[]) => void): void;
Expand Down
4 changes: 2 additions & 2 deletions packages/@best/agent/src/AgentApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class AgentApp {
handleIncomingConnection(socket: SocketIO.Socket) {
socket.on('benchmark_task', (data: BuildConfig) => {
const task = new BenchmarkTask(data, socket);
this.logger.event(socket.id, 'benchmark_task', { benchmarkName: data.benchmarkName }, false);
this.logger.event(socket.id, 'benchmark added', { benchmarkName: data.benchmarkName }, false);

socket.on('disconnect', () => {
this.queue.remove(task);
Expand All @@ -43,7 +43,7 @@ export class AgentApp {
this.runner.run(task);
} else {
task.socketConnection.emit('benchmark_enqueued', { pending: this.queue.size });
this.logger.event(task.socketConnection.id, 'benchmark_enqueued', { pending: this.queue.size });
this.logger.event(task.socketConnection.id, 'benchmark queued', { pending: this.queue.size });
}
}

Expand Down
23 changes: 9 additions & 14 deletions packages/@best/agent/src/BenchmarkRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { runBenchmark } from '@best/runner';
import BenchmarkTask from "./BenchmarkTask";
import { loadBenchmarkJob } from "./benchmark-loader";
import { x as extractTar } from 'tar';
import * as SocketIO from "socket.io";
import { RunnerOutputStream } from "@best/console-stream";
import AgentLogger from '@best/agent-logger';
import AgentLogger, { loggedSocket, LoggedSocket } from '@best/agent-logger';
import {
BenchmarkResultsSnapshot,
BenchmarkResultsState,
Expand All @@ -22,32 +21,28 @@ export enum RunnerStatus {
}

// @todo: make a Runner Stream, and add an interface type instead of the class.
function initializeForwarder(socket: SocketIO.Socket, logger: AgentLogger): RunnerOutputStream {
function initializeForwarder(socket: LoggedSocket): RunnerOutputStream {
return {
init() {},
finish() {},
onBenchmarkStart(benchmarkPath: string) {
if (socket.connected) {
if (socket.rawSocket.connected) {
socket.emit('running_benchmark_start', { entry: benchmarkPath });
logger.event(socket.id, 'running_benchmark_start', { entry: benchmarkPath })
}
},
onBenchmarkEnd(benchmarkPath: string) {
if (socket.connected) {
if (socket.rawSocket.connected) {
socket.emit('running_benchmark_end', { entry: benchmarkPath });
logger.event(socket.id, 'running_benchmark_end', { entry: benchmarkPath })
}
},
onBenchmarkError(benchmarkPath: string) {
if (socket.connected) {
if (socket.rawSocket.connected) {
socket.emit('running_benchmark_error', { entry: benchmarkPath });
logger.event(socket.id, 'running_benchmark_error', { entry: benchmarkPath });
}
},
updateBenchmarkProgress(state: BenchmarkResultsState, opts: BenchmarkRuntimeConfig) {
if (socket.connected) {
if (socket.rawSocket.connected) {
socket.emit('running_benchmark_update', { state, opts });
logger.throttle(socket.id, 'running_benchmark_update', { state, opts }, false);
}
},
} as RunnerOutputStream;
Expand Down Expand Up @@ -124,7 +119,8 @@ export default class BenchmarkRunner extends EventEmitter {

private async runBenchmark(task: BenchmarkTask) {
const { benchmarkName } = task;
const messenger = initializeForwarder(task.socketConnection, this.logger);
const taskSocket = loggedSocket(task.socketConnection, this.logger);
const messenger = initializeForwarder(taskSocket);

let results;
let error;
Expand All @@ -149,10 +145,9 @@ export default class BenchmarkRunner extends EventEmitter {

if (err) {
this.runningTask!.socketConnection.emit('benchmark_error', err.toString());
this.logger.event(this.runningTask!.socketConnection.id, 'benchmark_error', { err });
} else {
this.runningTask!.socketConnection.emit('benchmark_results', results);
this.logger.event(this.runningTask!.socketConnection.id, 'benchmark_results', results, false);
this.logger.event(this.runningTask!.socketConnection.id, 'benchmark results', { resultCount: results!.results.length }, false);
}
}

Expand Down

0 comments on commit d980055

Please sign in to comment.