Skip to content

Commit

Permalink
Added elapsed time tracking for the runTask method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanoostveen committed Aug 21, 2023
1 parent 0654ff8 commit 2986b34
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/taskrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ export interface TaskRunner {
runTask(command: string, args: string[], config: TaskConfig): Task;
}

let strip = (line: string) => /^\s*(.*?)\s*$/m.exec(line)![1];
function strip(line: string) {
return /^\s*(.*?)\s*$/m.exec(line)![1];
}

export let createDefaultTaskRunner = (): TaskRunner => {
export function createDefaultTaskRunner(): TaskRunner {
return {
runTask: (command: string, args: string[], config: TaskConfig) => {
runTask(command: string, args: string[], config: TaskConfig) {
let start = performance.now();
let loggerCategory = config.name;
let logger = config.logger;

Expand Down Expand Up @@ -75,6 +78,15 @@ export let createDefaultTaskRunner = (): TaskRunner => {

let result = new Promise<void>((resolve, reject) => {
task.on("close", (code: number) => {
let end = performance.now();
let elapsedTime = (end - start) / 1000;
logger.log(
loggerCategory,
`command ${readableCommand} ${args.join(
" "
)} took ${elapsedTime.toFixed(1)}s`
);

if (code === 0 || code === null) {
resolve();
} else {
Expand All @@ -85,13 +97,13 @@ export let createDefaultTaskRunner = (): TaskRunner => {

return {
result,
kill: () => {
kill() {
kill(task.pid!);
},
};
},
};
};
}

export let createWindowsTaskRunner = (): TaskRunner => {
let delegate = createDefaultTaskRunner();
Expand Down

0 comments on commit 2986b34

Please sign in to comment.