Made use of LoggingStopwatch

This commit is contained in:
Kir_Antipov 2022-07-05 18:02:45 +03:00
parent d097cc8471
commit 58a1f9bab8
2 changed files with 7 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import PublisherTarget from "./publishing/publisher-target";
import { getInputAsObject, mapNumberInput } from "./utils/input-utils"; import { getInputAsObject, mapNumberInput } from "./utils/input-utils";
import { getDefaultLogger } from "./utils/logger-utils"; import { getDefaultLogger } from "./utils/logger-utils";
import { retry } from "./utils/function-utils"; import { retry } from "./utils/function-utils";
import LoggingStopwatch from "./utils/logging-stopwatch";
async function main() { async function main() {
const commonOptions = getInputAsObject(); const commonOptions = getInputAsObject();
@ -25,8 +26,7 @@ async function main() {
const retryDelay = mapNumberInput(options.retryDelay); const retryDelay = mapNumberInput(options.retryDelay);
const publisher = publisherFactory.create(target, logger); const publisher = publisherFactory.create(target, logger);
logger.info(`Publishing assets to ${targetName}...`); const stopwatch = LoggingStopwatch.startNew(logger, `Publishing assets to ${targetName}...`, ms => `Successfully published assets to ${targetName} (in ${ms} ms)`);
const start = new Date();
await retry({ await retry({
func: () => publisher.publish(files, options), func: () => publisher.publish(files, options),
@ -38,8 +38,7 @@ async function main() {
} }
}); });
const end = new Date(); stopwatch.stop();
logger.info(`Successfully published assets to ${targetName} (in ${end.getTime() - start.getTime()} ms)`);
publishedTo.push(targetName); publishedTo.push(targetName);
} }

View file

@ -5,6 +5,7 @@ import PublisherTarget from "../publisher-target";
import Dependency from "../../metadata/dependency"; import Dependency from "../../metadata/dependency";
import DependencyKind from "../../metadata/dependency-kind"; import DependencyKind from "../../metadata/dependency-kind";
import { mapBooleanInput, mapEnumInput } from "../../utils/input-utils"; import { mapBooleanInput, mapEnumInput } from "../../utils/input-utils";
import LoggingStopwatch from "../../utils/logging-stopwatch";
enum UnfeatureMode { enum UnfeatureMode {
None = 0, None = 0,
@ -68,9 +69,8 @@ export default class ModrinthPublisher extends ModPublisher {
} }
private async unfeatureOlderVersions(id: string, token: string, unfeatureMode: UnfeatureMode, loaders: string[], gameVersions: string[]): Promise<void> { private async unfeatureOlderVersions(id: string, token: string, unfeatureMode: UnfeatureMode, loaders: string[], gameVersions: string[]): Promise<void> {
this.logger.info("Unfeaturing older Modrinth versions..."); const unfeaturedVersions = new Array<string>();
const start = new Date(); const stopwatch = LoggingStopwatch.startNew(this.logger, "Unfeaturing older Modrinth versions...", ms => `Successfully unfeatured: ${unfeaturedVersions.join(", ")} (in ${ms} ms)`);
const unfeaturedVersions = <string[]>[];
const versionSubset = hasFlag(unfeatureMode, UnfeatureMode.VersionSubset); const versionSubset = hasFlag(unfeatureMode, UnfeatureMode.VersionSubset);
const loaderSubset = hasFlag(unfeatureMode, UnfeatureMode.LoaderSubset); const loaderSubset = hasFlag(unfeatureMode, UnfeatureMode.LoaderSubset);
@ -92,8 +92,7 @@ export default class ModrinthPublisher extends ModPublisher {
} }
if (unfeaturedVersions.length) { if (unfeaturedVersions.length) {
const end = new Date(); stopwatch.stop();
this.logger.info(`Successfully unfeatured versions ${unfeaturedVersions.join(", ")} (in ${end.getTime() - start.getTime()} ms)`);
} else { } else {
this.logger.info("No versions to unfeature were found"); this.logger.info("No versions to unfeature were found");
} }