@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
30 lines (29 loc) • 1.02 kB
TypeScript
export interface RunScriptOptions {
/**
* Set it to a channel name (e.g 'backend', without #), so it will report to slack on runScript failure.
* Requires env.SLACK_WEBHOOK_URL to be set.
* Overrides env.SLACK_ON_FAILURE
*/
slackOnFailure?: string | false;
/**
* Set it to a channel name (e.g 'backend') to report to slack on runScript success.
* It will include the value returned to runScript.
*/
slackOnSuccess?: string | false;
}
/**
* Use it in your top-level scripts like this:
*
* runScript(async () => {
* await lalala()
* // my script goes on....
* })
*
* Advantages:
* - Works kind of like top-level await
* - No need to add `void`
* - No need to add `.then(() => process.exit()` (e.g to close DB connections)
* - No need to add `.catch(err => { console.error(err); process.exit(1) })`
* - Supports automatic failure reporting to Slack (!)
*/
export declare function runScriptWithSlack(fn: (...args: any[]) => any, opt?: RunScriptOptions): void;