import { WebClient } from "@slack/web-api";
import dayjs from "dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
error_started_at: string, // The start datetime of the latest job that failed
success_times: number, // The number of times the schedule succeeded before calling the recovery handler.
success_result: object, // The result of the latest successful job
success_started_at: string, // The start datetime of the latest successful job
slack: Slack,
channel: string,
) {
const baseUrl = process.env["WM_BASE_URL"];
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} recovered ${
success_times > 1 ? (success_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*Schedule <${scheduleUrl}|${schedule_path}> recovered*${
success_times > 1 ? (" " + success_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure at: ${
dayjs(error_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`,
},
},
],
},
{
color: "#00ff00",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last success at: ${
dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n\`\`\`\n${JSON.stringify(success_result)}\n\`\`\``,
},
},
],
},
],
});
}
Submitted by hugo697 64 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
error_started_at: string, // The start datetime of the latest job that failed
success_times: number, // The number of times the schedule succeeded before calling the recovery handler.
success_result: object, // The result of the latest successful job
success_started_at: string, // The start datetime of the latest successful job
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} recovered ${
success_times > 1 ? (success_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*Schedule <${scheduleUrl}|${schedule_path}> recovered*${
success_times > 1 ? (" " + success_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure at: ${
dayjs(error_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`,
},
},
],
},
{
color: "#00ff00",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last success at: ${
dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n\`\`\`\n${JSON.stringify(success_result)}\n\`\`\``,
},
},
],
},
],
});
}
Submitted by hugo697 70 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
error_started_at: string, // The start datetime of the latest job that failed
success_times: number, // The number of times the schedule succeeded before calling the recovery handler.
success_result: object, // The result of the latest successful job
success_started_at: string, // The start datetime of the latest successful job
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} recovered ${
success_times > 1 ? (success_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*Schedule <${scheduleUrl}|${schedule_path}> recovered*${
success_times > 1 ? (" " + success_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure at: ${
dayjs(error_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`,
},
},
],
},
{
color: "#00ff00",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last success at: ${
dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n\`\`\`\n${success_result}\n\`\`\``,
},
},
],
},
],
});
}
Submitted by hugo697 449 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
started_at: string, // The start datetime of the latest job that failed
failed_times: number, // Minimum number of times the schedule failed before calling the error handler
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} failed ${
failed_times > 1 ? (failed_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Schedule <${scheduleUrl}|${schedule_path}> failed${
failed_times > 1 ? (" " + failed_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
color: "#ff0000",
"blocks": [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure at: ${
dayjs(started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`,
},
}],
},
],
});
}
Submitted by hugo697 449 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
error_started_at: string, // The start datetime of the latest job that failed
success_times: number, // The number of times the schedule succeeded before calling the recovery handler.
success_result: object, // The result of the latest successful job
success_started_at: string, // The start datetime of the latest successful job
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} recovered ${
success_times > 1 ? (success_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Schedule <${scheduleUrl}|${schedule_path}> recovered${
success_times > 1 ? (" " + success_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
color: "#ff0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure at: ${
dayjs(error_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`,
},
},
],
},
{
color: "#0000ff",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last success at: ${
dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n\`\`\`\n${success_result}\n\`\`\``,
},
},
],
},
],
});
}
Submitted by hugo697 449 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
error_started_at: string, // The start datetime of the latest job that failed
success_times: number, // The number of times the schedule succeeded before calling the recovery handler.
success_result: object, // The result of the latest successful job
success_started_at: string, // The start datetime of the latest successful job
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} recovered ${
success_times > 1 ? (success_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Schedule <${scheduleUrl}|${schedule_path}> recovered${
success_times > 1 ? (" " + success_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
color: "#ff0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure: ${
dayjs(error_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`,
},
},
],
},
{
color: "#0000ff",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last success: ${
dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n\`\`\`\n${success_result}\n\`\`\``,
},
},
],
},
],
});
}
Submitted by hugo697 449 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
function formatError(error: any) {
if (error.stack && error.name && error.message) {
return `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
} else {
return `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``;
}
}
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
started_at: string, // The start datetime of the latest job that failed
failed_times: number, // Minimum number of times the schedule failed before calling the error handler
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} failed ${
failed_times > 1 ? (failed_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Schedule <${scheduleUrl}|${schedule_path}> failed${
failed_times > 1 ? (" " + failed_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
color: "#ff0000",
"blocks": [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure at: ${
dayjs(started_at).format("DD.MM.YYYY HH:mm Z")
}\n${formatError(error)}`,
},
}],
},
],
});
}
Submitted by hugo697 449 days ago
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.0/mod.ts";
import dayjs from "npm:dayjs";
type Slack = {
token: string;
};
export async function main(
path: string, // The path of the script or flow that errored
is_flow: boolean, // Whether the runnable is a flow
schedule_path: string, // The path of the schedule
error: object, // The error details
error_started_at: string, // The start datetime of the latest job that failed
success_times: number, // The number of times the schedule succeeded before calling the recovery handler.
success_result: object, // The result of the latest successful job
success_started_at: string, // The start datetime of the latest successful job
slack: Slack,
channel: string,
) {
const baseUrl = Deno.env.get("WM_BASE_URL");
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path);
const runnableUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path;
const web = new WebClient(slack.token);
await web.chat.postMessage({
channel,
text: `Schedule ${schedule_path} recovered ${
success_times > 1 ? (success_times + " times in a row") : ""
}`,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Schedule <${scheduleUrl}|${schedule_path}> recovered${
success_times > 1 ? (" " + success_times + " times in a row") : ""
}:\n- ${is_flow ? "Flow" : "Script"}: <${runnableUrl}|${path}>`,
},
},
],
attachments: [
{
color: "#ff0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last failure: ${
dayjs(error_started_at).format("DD.MM.YYYY HH:mm (Z)")
}`,
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``,
},
},
],
},
{
color: "#0000ff",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Last success: ${
dayjs(success_started_at).format("DD.MM.YYYY HH:mm (Z)")
}`,
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `\`\`\`\n${success_result}\n\`\`\``,
},
},
],
},
],
});
}
Submitted by hugo697 449 days ago