@promise-watch/core
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -26,9 +26,2 @@ "use strict"; | ||
exports.executeJobs = executeJobs; | ||
function shutdown() { | ||
(0, recursively_run_1.haltRecursion)(); | ||
console.log("HALTING RECURSION"); | ||
process.exit(0); | ||
} | ||
process.on("SIGINT", shutdown); | ||
process.on("SIGTERM", shutdown); | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,5 @@ | ||
import { SendOptions } from "../types"; | ||
export declare class ConsoleNotifier { | ||
send(options: SendOptions): Promise<void>; | ||
import { Notifier, SendOptions } from "../types"; | ||
export declare class ConsoleNotifier implements Notifier { | ||
sendError(options: SendOptions): Promise<void>; | ||
sendRecovered(options: SendOptions): Promise<void>; | ||
} |
@@ -5,7 +5,10 @@ "use strict"; | ||
class ConsoleNotifier { | ||
async send(options) { | ||
console.log(`${options.title}: ${options.body}`); | ||
async sendError(options) { | ||
console.error(options.title, options.body); | ||
} | ||
async sendRecovered(options) { | ||
console.log(options.title, options.body); | ||
} | ||
} | ||
exports.ConsoleNotifier = ConsoleNotifier; | ||
//# sourceMappingURL=console-notifier.js.map |
@@ -19,7 +19,18 @@ "use strict"; | ||
}; | ||
let passed = false; | ||
await runAttempt() | ||
.catch(() => runAttempt()) | ||
.catch(() => { | ||
passed = false; | ||
return runAttempt(); | ||
}) | ||
.catch(err => (0, send_notifications_1.sendErrorNotifications)(name, err.message, notifiers)); | ||
if (alive) { | ||
await (0, sleep_1.sleep)(options.interval * 1000); | ||
if (passed) { | ||
await (0, sleep_1.sleep)(options.interval * 1000); | ||
await recursivelyRun(page, notifiers); | ||
return; | ||
} | ||
if (!options.tryAgainImmediately) { | ||
await (0, sleep_1.sleep)(options.interval * 1000); | ||
} | ||
await recursivelyRun(page, notifiers); | ||
@@ -29,2 +40,9 @@ } | ||
exports.recursivelyRun = recursivelyRun; | ||
function shutdown() { | ||
haltRecursion(); | ||
console.log("HALTING RECURSION"); | ||
process.exit(0); | ||
} | ||
process.on("SIGINT", shutdown); | ||
process.on("SIGTERM", shutdown); | ||
//# sourceMappingURL=recursively-run.js.map |
@@ -5,5 +5,6 @@ "use strict"; | ||
const time_1 = require("./utils/time"); | ||
async function sendNotifications({ title, body, notifiers, isSuccess = false }) { | ||
async function sendNotifications({ notifiers, isSuccess, ...message }) { | ||
for (const notify of notifiers) { | ||
await notify.send({ title, body, isSuccess }).catch(console.error); | ||
const send = isSuccess ? notify.sendRecovered : notify.sendError; | ||
await send(message).catch(console.error); | ||
} | ||
@@ -10,0 +11,0 @@ } |
@@ -7,4 +7,5 @@ export declare type RunPage = { | ||
export declare type RunOptions = { | ||
interval: number; | ||
notifiers?: Notifier[]; | ||
interval: number; | ||
tryAgainImmediately?: boolean; | ||
}; | ||
@@ -19,6 +20,6 @@ export declare type ExecuteOptions = { | ||
body: string; | ||
isSuccess?: boolean; | ||
}; | ||
export declare type Notifier = { | ||
send(options: SendOptions): Promise<void>; | ||
sendError(options: SendOptions): Promise<void>; | ||
sendRecovered(options: SendOptions): Promise<void>; | ||
}; | ||
@@ -25,0 +26,0 @@ export declare type SendNotifications = { |
{ | ||
"name": "@promise-watch/core", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "author": "Jason Raimondi <jason@raimondi.us> (https://jasonraimondi.com)", |
@@ -1,2 +0,2 @@ | ||
import { haltRecursion, recursivelyRun } from "./recursively-run"; | ||
import { recursivelyRun } from "./recursively-run"; | ||
import { ExecuteOptions } from "./types"; | ||
@@ -15,10 +15,1 @@ import { importRunsFromPath } from "./import-runs"; | ||
} | ||
function shutdown() { | ||
haltRecursion(); | ||
console.log("HALTING RECURSION"); | ||
process.exit(0); | ||
} | ||
process.on("SIGINT", shutdown); | ||
process.on("SIGTERM", shutdown); |
@@ -1,7 +0,11 @@ | ||
import { SendOptions } from "../types"; | ||
import { Notifier, SendOptions } from "../types"; | ||
export class ConsoleNotifier { | ||
async send(options: SendOptions) { | ||
console.log(`${options.title}: ${options.body}`); | ||
export class ConsoleNotifier implements Notifier{ | ||
async sendError(options: SendOptions): Promise<void> { | ||
console.error(options.title, options.body); | ||
} | ||
async sendRecovered(options: SendOptions): Promise<void> { | ||
console.log(options.title, options.body); | ||
} | ||
} |
import { haltRecursion, recursivelyRun } from "./recursively-run"; | ||
import { ConsoleNotifier } from "./notifiers/console-notifier"; | ||
import { RunPage } from "./types"; | ||
describe("recursively run", () => { | ||
const page = { | ||
const page: RunPage = { | ||
name: "test run", | ||
@@ -7,0 +8,0 @@ run: async () => { |
@@ -20,11 +20,38 @@ import { Notifier, RunPage } from "./types"; | ||
let passed = false; | ||
// try runs twice before sending an error notification | ||
await runAttempt() | ||
.catch(() => runAttempt()) | ||
.catch(() => { | ||
passed = false; | ||
return runAttempt(); | ||
}) | ||
.catch(err => sendErrorNotifications(name, err.message, notifiers)); | ||
// passed wait | ||
// failed tryAgainImmediately: false wait | ||
// failed tryAgainImmediately: true no-wait | ||
if (alive) { | ||
await sleep(options.interval * 1000); | ||
if (passed) { | ||
await sleep(options.interval * 1000); | ||
await recursivelyRun(page, notifiers); | ||
return; | ||
} | ||
if (!options.tryAgainImmediately) { | ||
await sleep(options.interval * 1000); | ||
} | ||
await recursivelyRun(page, notifiers); | ||
} | ||
} | ||
function shutdown() { | ||
haltRecursion(); | ||
console.log("HALTING RECURSION"); | ||
process.exit(0); | ||
} | ||
process.on("SIGINT", shutdown); | ||
process.on("SIGTERM", shutdown); |
import { Notifier, SendNotifications } from "./types"; | ||
import { howLongAgo } from "./utils/time"; | ||
async function sendNotifications({ title, body, notifiers, isSuccess = false }: SendNotifications) { | ||
async function sendNotifications({ notifiers, isSuccess, ...message }: SendNotifications) { | ||
for (const notify of notifiers) { | ||
await notify.send({ title, body, isSuccess }).catch(console.error); | ||
const send = isSuccess ? notify.sendRecovered : notify.sendError; | ||
await send(message).catch(console.error); | ||
} | ||
@@ -8,0 +9,0 @@ } |
@@ -8,4 +8,5 @@ export type RunPage = { | ||
export type RunOptions = { | ||
interval: number; | ||
notifiers?: Notifier[]; | ||
interval: number; | ||
tryAgainImmediately?: boolean; | ||
}; | ||
@@ -22,9 +23,9 @@ | ||
body: string; | ||
isSuccess?: boolean; | ||
}; | ||
export type Notifier = { | ||
send(options: SendOptions): Promise<void>; | ||
sendError(options: SendOptions): Promise<void>; | ||
sendRecovered(options: SendOptions): Promise<void>; | ||
}; | ||
export type SendNotifications = { title: string; body: string; notifiers: Notifier[]; isSuccess?: boolean }; |
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
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
34837
58
595