@promise-watch/core
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -23,4 +23,3 @@ "use strict"; | ||
const invalidPageOptions = { | ||
run: async () => { | ||
}, | ||
run: async () => { }, | ||
}; | ||
@@ -27,0 +26,0 @@ expect((0, filter_runs_1.filterRunsWithoutRequiredFields)([invalidPageOptions, validPage])).toStrictEqual([validPage]); |
@@ -27,3 +27,4 @@ "use strict"; | ||
const files = await (0, glob_promise_1.glob)(globPath); | ||
const imports = await Promise.all(files.map(f => Promise.resolve().then(() => __importStar(require((0, path_1.resolve)(dir, "../", f)))))); | ||
const promises = files.map(f => (0, path_1.resolve)(dir, "../", f)); | ||
const imports = await Promise.all(promises.map(f => Promise.resolve().then(() => __importStar(require(f))))); | ||
return imports.map((page, idx) => { | ||
@@ -30,0 +31,0 @@ var _a; |
@@ -20,5 +20,5 @@ "use strict"; | ||
async function executeJobs(options) { | ||
const { dir, notifiers = [], globPath = "runs/**/*.{js,ts}", } = options; | ||
const files = await (0, import_runs_1.importRunsFromPath)(globPath, dir); | ||
const runs = (0, filter_runs_1.filterRunsWithoutRequiredFields)(files); | ||
const { dir, notifiers = [], globPath = "runs/**/*.{js,ts}" } = options; | ||
let runs = await (0, import_runs_1.importRunsFromPath)(globPath, dir); | ||
runs = (0, filter_runs_1.filterRunsWithoutRequiredFields)(runs); | ||
await Promise.allSettled(runs.map(run => (0, recursively_run_1.recursivelyRun)(run, notifiers))); | ||
@@ -25,0 +25,0 @@ } |
@@ -19,13 +19,5 @@ "use strict"; | ||
}; | ||
try { | ||
await runAttempt(); | ||
} | ||
catch (err) { | ||
try { | ||
await runAttempt(); | ||
} | ||
catch (err) { | ||
await (0, send_notifications_1.sendErrorNotifications)(name, err.message, notifiers); | ||
} | ||
} | ||
await runAttempt() | ||
.catch(() => runAttempt()) | ||
.catch(err => (0, send_notifications_1.sendErrorNotifications)(name, err.message, notifiers)); | ||
if (alive) { | ||
@@ -32,0 +24,0 @@ await (0, sleep_1.sleep)(options.interval * 1000); |
@@ -5,3 +5,3 @@ "use strict"; | ||
function howLongAgo(milliseconds) { | ||
const numberEnding = (n) => (n > 1) ? "s" : ""; | ||
const numberEnding = (n) => (n > 1 ? "s" : ""); | ||
const seconds = Math.floor((Date.now() - milliseconds) / 1000); | ||
@@ -8,0 +8,0 @@ if (seconds > 60) { |
{ | ||
"name": "@promise-watch/core", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "author": "Jason Raimondi <jason@raimondi.us> (https://jasonraimondi.com)", |
@@ -8,3 +8,3 @@ import { filterRunsWithoutRequiredFields } from "./filter-runs"; | ||
run: async () => {}, | ||
} | ||
}; | ||
@@ -27,4 +27,3 @@ beforeEach(() => { | ||
const invalidPageOptions: any = { | ||
run: async () => { | ||
}, | ||
run: async () => {}, | ||
}; | ||
@@ -35,2 +34,1 @@ expect(filterRunsWithoutRequiredFields([invalidPageOptions, validPage])).toStrictEqual([validPage]); | ||
}); | ||
@@ -13,3 +13,3 @@ import { RunPage } from "./types"; | ||
if (errors.length) { | ||
console.log(`${next.name} has errors and was skipped:`) | ||
console.log(`${next.name} has errors and was skipped:`); | ||
console.log(errors.join("\n"), "\n"); | ||
@@ -21,3 +21,2 @@ return [...prev]; | ||
}, [] as RunPage[]); | ||
} |
@@ -7,3 +7,4 @@ import { glob } from "./utils/glob-promise"; | ||
const files = await glob(globPath); | ||
const imports = await Promise.all(files.map(f => import(resolve(dir, "../", f)))); | ||
const promises = files.map(f => resolve(dir, "../", f)); | ||
const imports = await Promise.all(promises.map(f => import(f))); | ||
return imports.map((page, idx) => ({ | ||
@@ -14,2 +15,2 @@ name: page.name ?? files[idx].replace("runs/", ""), | ||
})); | ||
} | ||
} |
@@ -6,13 +6,9 @@ import { haltRecursion, recursivelyRun } from "./recursively-run"; | ||
export * from "./notifiers/console-notifier" | ||
export * from "./notifiers/console-notifier"; | ||
export * from "./types"; | ||
export async function executeJobs(options: ExecuteOptions) { | ||
const { | ||
dir, | ||
notifiers = [], | ||
globPath = "runs/**/*.{js,ts}", | ||
} = options; | ||
const files = await importRunsFromPath(globPath, dir); | ||
const runs = filterRunsWithoutRequiredFields(files); | ||
const { dir, notifiers = [], globPath = "runs/**/*.{js,ts}" } = options; | ||
let runs = await importRunsFromPath(globPath, dir); | ||
runs = filterRunsWithoutRequiredFields(runs); | ||
await Promise.allSettled(runs.map(run => recursivelyRun(run, notifiers))); | ||
@@ -19,0 +15,0 @@ } |
@@ -21,11 +21,5 @@ import { Notifier, RunPage } from "./types"; | ||
// try runs twice before sending an error notification | ||
try { | ||
await runAttempt(); | ||
} catch (err: any) { | ||
try { | ||
await runAttempt(); | ||
} catch (err: any) { | ||
await sendErrorNotifications(name, err.message, notifiers); | ||
} | ||
} | ||
await runAttempt() | ||
.catch(() => runAttempt()) | ||
.catch(err => sendErrorNotifications(name, err.message, notifiers)); | ||
@@ -36,2 +30,2 @@ if (alive) { | ||
} | ||
} | ||
} |
import { Notifier, SendNotifications } from "./types"; | ||
import { howLongAgo } from "./utils/time"; | ||
async function sendNotifications({ title, body, notifiers, isSuccess = false }: SendNotifications) { | ||
@@ -27,2 +26,2 @@ for (const notify of notifiers) { | ||
} | ||
} | ||
} |
@@ -28,2 +28,2 @@ export type RunPage = { | ||
export type SendNotifications = { title: string; body: string; notifiers: Notifier[]; isSuccess?: boolean; } | ||
export type SendNotifications = { title: string; body: string; notifiers: Notifier[]; isSuccess?: boolean }; |
export function howLongAgo(milliseconds: number) { | ||
const numberEnding = (n: number) => (n > 1) ? "s" : ""; | ||
const numberEnding = (n: number) => (n > 1 ? "s" : ""); | ||
@@ -7,4 +7,4 @@ const seconds = Math.floor((Date.now() - milliseconds) / 1000); | ||
if (seconds > 60) { | ||
const minutes = Math.floor(seconds / 60) | ||
const secondsLeft = Math.floor(seconds % 60) | ||
const minutes = Math.floor(seconds / 60); | ||
const secondsLeft = Math.floor(seconds % 60); | ||
return minutes + " minute" + numberEnding(minutes) + " " + secondsLeft + " second" + numberEnding(secondsLeft); | ||
@@ -11,0 +11,0 @@ } |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
30577
54
517
0