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) {
const formatted = `*${error.name}: ${error.message}*\`\`\`\n${error.stack}\n\`\`\``;
if (formatted.length > 2900) {
return `\`\`\`\n${JSON.stringify(error, null, 2).substring(0, 2900)}...\n(truncated)\n\`\`\``;
} else {
return formatted
}
} else {
const stringified = JSON.stringify(error, null, 2);
if (stringified.length > 2900) {
return `\`\`\`\n${stringified.substring(0, 2900)}...\n(truncated)\n\`\`\``;
} else {
return `\`\`\`\n${stringified}\n\`\`\``;
}
}
}
export async function main(
workspace_id: string,
job_id: string, // The UUID of the job that errored
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 = process.env["WM_BASE_URL"];
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path) + "&workspace=" + encodeURIComponent(workspace_id);
const scriptOrFlowRunUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path + "?workspace=" + encodeURIComponent(workspace_id);
const web = new WebClient(slack.token);
const jobRunUrl = baseUrl + "/run/" + job_id + "?workspace=" + encodeURIComponent(workspace_id);
let rawText = ""
if (schedule_path === undefined) {
rawText = `${schedule_path != undefined ? `Schedule ${schedule_path} failed ` : ""}${failed_times > 1 ? (failed_times + " times in a row") : ""}`
} else {
rawText = `Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}> failed ${failed_times > 1 ? (failed_times + " times in a row") : ""}`
}
let mdText = ""
if (schedule_path === undefined) {
mdText = `*Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"} <${scriptOrFlowRunUrl}|${path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:`
} else {
mdText = `*Schedule <${scheduleUrl}|${schedule_path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:\n- Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}>`
}
const errorText = `Last failure at: ${dayjs(started_at).format("DD.MM.YYYY HH:mm (Z)")
}\n${formatError(error)}`
await web.chat.postMessage({
channel,
text: rawText,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": mdText,
},
},
],
attachments: [
{
color: "#ff0000",
"blocks": [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": errorText,
},
}],
fallback: errorText
},
],
});
}
Submitted by hugo697 53 days ago
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 {
const stringified = JSON.stringify(error, null, 2);
if (stringified.length > 2900) {
return `\`\`\`\n${stringified.substring(0, 2900)}...\n(truncated)\n\`\`\``;
} else {
return `\`\`\`\n${stringified}\n\`\`\``;
}
}
}
export async function main(
workspace_id: string,
job_id: string, // The UUID of the job that errored
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 = process.env["WM_BASE_URL"];
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path) + "&workspace=" + encodeURIComponent(workspace_id);
const scriptOrFlowRunUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path + "?workspace=" + encodeURIComponent(workspace_id);
const web = new WebClient(slack.token);
const jobRunUrl = baseUrl + "/run/" + job_id + "?workspace=" + encodeURIComponent(workspace_id);
let rawText = ""
if (schedule_path === undefined) {
rawText = `${schedule_path != undefined ? `Schedule ${schedule_path} failed ` : ""}${failed_times > 1 ? (failed_times + " times in a row") : ""}`
} else {
rawText = `Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}> failed ${failed_times > 1 ? (failed_times + " times in a row") : ""}`
}
let mdText = ""
if (schedule_path === undefined) {
mdText = `*Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"} <${scriptOrFlowRunUrl}|${path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:`
} else {
mdText = `*Schedule <${scheduleUrl}|${schedule_path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:\n- Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}>`
}
await web.chat.postMessage({
channel,
text: rawText,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": mdText,
},
},
],
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 53 days ago
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(
workspace_id: string,
job_id: string, // The UUID of the job that errored
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 = process.env["WM_BASE_URL"];
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path) + "&workspace=" + encodeURIComponent(workspace_id);
const scriptOrFlowRunUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path + "?workspace=" + encodeURIComponent(workspace_id);
const web = new WebClient(slack.token);
const jobRunUrl = baseUrl + "/run/" + job_id + "?workspace=" + encodeURIComponent(workspace_id);
let rawText = ""
if (schedule_path === undefined) {
rawText = `${schedule_path != undefined ? `Schedule ${schedule_path} failed ` : ""}${failed_times > 1 ? (failed_times + " times in a row") : ""}`
} else {
rawText = `Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}> failed ${failed_times > 1 ? (failed_times + " times in a row") : ""}`
}
let mdText = ""
if (schedule_path === undefined) {
mdText = `*Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"} <${scriptOrFlowRunUrl}|${path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:`
} else {
mdText = `*Schedule <${scheduleUrl}|${schedule_path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:\n- Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}>`
}
await web.chat.postMessage({
channel,
text: rawText,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": mdText,
},
},
],
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 101 days ago
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(
workspace_id: string,
job_id: string, // The UUID of the job that errored
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 = process.env["WM_BASE_URL"];
const scheduleUrl = baseUrl + "/runs?schedule_path=" +
encodeURIComponent(schedule_path) + "&workspace=" + encodeURIComponent(workspace_id);
const scriptOrFlowRunUrl = baseUrl + (is_flow ? "/flows/get/" : "/scripts/get/") +
path + "?workspace=" + encodeURIComponent(workspace_id);
const web = new WebClient(slack.token);
const jobRunUrl = baseUrl + "/run/" + job_id + "?workspace=" + encodeURIComponent(workspace_id);
let rawText = ""
if (schedule_path === undefined) {
rawText = `${schedule_path != undefined ? `Schedule ${schedule_path} failed ` : ""}${failed_times > 1 ? (failed_times + " times in a row") : ""}`
} else {
rawText = `Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}> failed ${failed_times > 1 ? (failed_times + " times in a row") : ""}`
}
let mdText = ""
if (schedule_path === undefined) {
mdText = `*Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"} <${scriptOrFlowRunUrl}|${path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:`
} else {
mdText = `*Schedule <${scheduleUrl}|${schedule_path}> failed*${failed_times > 1 ? (" " + failed_times + " times in a row") : ""}:\n- Run <${jobRunUrl}|${job_id}> of ${is_flow ? "flow" : "script"}: <${scriptOrFlowRunUrl}|${path}>`
}
await web.chat.postMessage({
channel,
text: rawText,
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": mdText,
},
},
],
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 101 days ago