Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ms-cloudpack/task-reporter

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/task-reporter - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

lib/configs.d.ts

1

lib/index.d.ts

@@ -6,1 +6,2 @@ export { blue, bold, clearLine, cyan, darkGrey, gradient, green, grey, lightRed, magenta, moveDownLines, moveUpLines, red, white, yellow, } from './ansiHelpers.js';

export { TaskReporter, type TaskReporterOptions } from './TaskReporter.js';
export { debugLoggingConfig, defaultLoggingConfig, noLoggingConfig, verboseLoggingConfig } from './configs.js';

@@ -6,2 +6,3 @@ export { blue, bold, clearLine, cyan, darkGrey, gradient, green, grey, lightRed, magenta, moveDownLines, moveUpLines, red, white, yellow, } from './ansiHelpers.js';

export { TaskReporter } from './TaskReporter.js';
export { debugLoggingConfig, defaultLoggingConfig, noLoggingConfig, verboseLoggingConfig } from './configs.js';
//# sourceMappingURL=index.js.map

10

lib/TaskReporter.d.ts
import { TaskReporterTask, type TaskReporterTaskResult } from './TaskReporterTask.js';
export interface TaskReporterOptions {
productName: string;
version: string;
productName?: string;
version?: string;
description?: string;

@@ -36,9 +36,9 @@ showConsoleLog?: boolean;

private _writer;
private _firstTaskStartTime;
private _totalDuration;
private _pendingTasks;
private _runningTasks;
private _runningTaskStickies;
private _completedTasks;
private _completeReason;
constructor(options: TaskReporterOptions);
private _hasCompleted;
constructor(options?: TaskReporterOptions);
/** Set options. */

@@ -45,0 +45,0 @@ setOptions(options: TaskReporterOptions): void;

@@ -7,2 +7,5 @@ import { Writer } from './Writer.js';

import { getTimestamp } from './getTimestamp.js';
import { SpinningSticky } from './SpinningSticky.js';
/** Controls how many tasks should be displayed in the pending sticky list. */
const maxRunningTasksShown = 5;
const statusCharacter = {

@@ -49,10 +52,10 @@ running: yellow('!'),

export class TaskReporter {
constructor(options) {
constructor(options = {}) {
this._options = options;
this._firstTaskStartTime = 0;
this._totalDuration = 0;
this._writer = new Writer();
this._pendingTasks = new Set();
this._runningTasks = new Set();
this._runningTaskStickies = new Map();
this._completedTasks = [];
this._hasCompleted = false;
this._reportProductName();

@@ -73,6 +76,2 @@ // Catch console.log messages and print them using this.write.

task.on('start', () => {
if (!this._firstTaskStartTime) {
this._firstTaskStartTime = performance.now();
this._totalDuration = 0;
}
this._pendingTasks.delete(task);

@@ -87,2 +86,7 @@ this._runningTasks.add(task);

this._reportTaskComplete(task);
const sticky = this._runningTaskStickies.get(task);
if (sticky) {
sticky.remove();
this._runningTaskStickies.delete(task);
}
this._updateStickies();

@@ -132,6 +136,7 @@ });

complete(completeReason) {
this._totalDuration = performance.now() - this._firstTaskStartTime;
this._pendingTasks.forEach((task) => task.complete({ status: 'skip', message: completeReason }));
this._runningTasks.forEach((task) => task.complete({ status: 'abort', message: completeReason }));
this._completedTasks = [...this._completedTasks, ...this._pendingTasks, ...this._runningTasks];
this._pendingTasks = new Set();
this._runningTasks = new Set();
this._writer.stickies = [];

@@ -215,3 +220,6 @@ this._completeReason = completeReason;

summaryMessage && this._writer.write(`Summary: ${this._completeReason}\n${summaryMessage}`);
this._writer.write(`Done in ${formatTime(this._totalDuration)}.`);
if (this._hasCompleted) {
throw new Error(`TaskReporter has already completed.`);
}
this._hasCompleted = true;
}

@@ -226,9 +234,21 @@ _updateStickies() {

: '';
this._writer.stickies = [
const summaryStickies = [
'',
`${darkGrey(`──┤`)} Waiting: ${yellow(this._pendingTasks.size)} ${darkGrey(`├──┤`)} Completed: ${green(this._completedTasks.length)} / ${green(totalTasks)}${percentage} ${darkGrey(`├──`)}`,
...(this._runningTasks.size ? ['', ...Array.from(this._runningTasks).map((task) => task.sticky)] : []),
];
const runningTaskStickies = [
...Array.from(this._runningTasks)
.slice(0, maxRunningTasksShown)
.map((task) => {
if (!this._runningTaskStickies.has(task)) {
this._runningTaskStickies.set(task, new SpinningSticky(task.name));
}
return this._runningTaskStickies.get(task);
}),
this._runningTasks.size > maxRunningTasksShown &&
`${yellow(`(+${this._runningTasks.size - maxRunningTasksShown} more...)`)}`,
].filter(Boolean);
this._writer.stickies = [...summaryStickies, ...runningTaskStickies];
}
}
//# sourceMappingURL=TaskReporter.js.map
/// <reference types="node" resolution-mode="require"/>
import { EventEmitter } from 'events';
import type { Sticky } from './Sticky.js';
export type TaskReporterTaskStatus = 'idle' | 'pending' | 'running' | 'pass' | 'complete' | 'fail' | 'abort' | 'skip' | 'log' | 'info' | 'warn' | 'error' | 'debug';

@@ -22,3 +21,2 @@ export interface TaskReporterTaskResult {

extended?: string;
sticky?: Sticky;
forceShow?: boolean;

@@ -25,0 +23,0 @@ constructor(name: string);

import { EventEmitter } from 'events';
import { SpinningSticky } from './SpinningSticky.js';
export class TaskReporterTask extends EventEmitter {

@@ -12,3 +11,2 @@ constructor(name) {

this.timeStarted = performance.now();
this.sticky = new SpinningSticky(this.name);
this.emit('start');

@@ -15,0 +13,0 @@ }

import { TaskReporter, bulletedList, bold } from './index.js';
import { defaultLoggingConfig } from './configs.js';
//const allIntervals: Set<NodeJS.Timer> = [];
const allTimeouts = new Set();
// function interval(cb: () => void, ms: number) {
// const id = setInterval(() => cb);
// allIntervals.add(id);
// }
function timeout(cb, ms) {
const id = setTimeout(() => {
allTimeouts.delete(id);
cb();
}, ms);
allTimeouts.add(id);
}
function cleanup() {
allTimeouts.forEach(clearTimeout);
allTimeouts.clear();
// allIntervals.forEach(clearInterval);
// allIntervals.clear();
}
function start() {

@@ -10,19 +30,7 @@ let count = 0;

description: `running tasks with ${bold(`15`)} workers`,
showCompleted: false,
showConsoleDebug: true,
showConsoleError: true,
showConsoleInfo: true,
showConsoleLog: true,
showConsoleWarn: true,
showErrors: true,
showPending: true,
showProgress: true,
showStarted: false,
showSummary: true,
showTaskDetails: true,
showTaskExtended: true,
...defaultLoggingConfig,
});
const addMoreTasks = () => {
if (activeTasks.size < 3) {
const tasksToAdd = Math.max(2, Math.round(Math.random() * 4));
const tasksToAdd = Math.max(2, Math.round(Math.random() * 40));
for (let i = 0; i < tasksToAdd; i++) {

@@ -34,5 +42,5 @@ const timeToStart = Math.round(Math.random() * 4000);

activeTasks.add(runningTask);
setTimeout(() => {
timeout(() => {
runningTask.start();
setTimeout(() => {
timeout(() => {
activeTasks.delete(runningTask);

@@ -46,2 +54,5 @@ taskShouldPass

});
if (activeTasks.size === 0) {
taskReporter.complete('All tasks complete');
}
}, timeToComplete);

@@ -52,11 +63,15 @@ }, timeToStart);

};
setInterval(addMoreTasks, 1000);
setInterval(() => console.log('I am a console.log message.'), 1000);
setInterval(() => console.info('I am a console.info message.'), 2000);
setInterval(() => console.warn('I am a console.warn message.'), 3000);
setInterval(() => console.error('I am a console.error message.'), 4000);
addMoreTasks();
// allIntervals.push(
// setInterval(addMoreTasks, 1000),
// setInterval(() => console.log('I am a console.log message.'), 1000),
// setInterval(() => console.info('I am a console.info message.'), 2000),
// setInterval(() => console.warn('I am a console.warn message.'), 3000),
// setInterval(() => console.error('I am a console.error message.'), 4000),
// );
// When ctrl-c is pressed, stop the task logger and print summary.
process.on('SIGINT', () => {
taskReporter.complete('User canceled');
process.exit(0);
cleanup();
// process.exit(0);
});

@@ -63,0 +78,0 @@ }

{
"name": "@ms-cloudpack/task-reporter",
"version": "0.0.2",
"version": "0.1.0",
"description": "Helpers for logging tasks to the console.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -70,1 +70,15 @@ # @ms-cloudpack/task-reporter

```
4. When all your tasks are completed, or if you encounted an exit-early scenario, call `reporter.complete('reason')`
to end task logging:
```ts
// You can instruct the reporter to complete when all tasks are done.
reporter.completeWhenTasksDone();
// Or, you can manually tell it to complete at any point. For example, you may want to complete things when the
// users hits ctrl-c. Prematurely completing means pending tasks will be skipped and running tasks will be aborted.
process.on('SIGINT', () => {
reporter.complete('User hit Ctrl-C');
});
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc