Edits history of script submission #1030 for ' Schedule error handler (slack)'

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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 384 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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 398 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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 950 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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_path != undefined ? `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 hugo698 1020 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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 1020 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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 1020 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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
      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: ${
                  dayjs(started_at).format("DD.MM.YYYY HH:mm Z")
                }`,
              },
            }, {
              "type": "section",
              "text": {
                "type": "mrkdwn",
                "text": `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``,
              },
            }],
          },
        ],
      });
    }
    

    Submitted by hugo697 1021 days ago

  • deno
    import { WebClient } from "https://deno.land/x/[email protected]/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.
      schedule_path: string, // The path of the schedule.
      error: object, // The error details.
      failed_times: number, // The number of times the schedule failed before calling the error handler.
      started_at: string, // The start datetime of the latest job that failed.
      slack: Slack,
      channel: string,
    ) {
      const baseUrl = Deno.env.get("WM_BASE_URL");
      const scheduleUrl = baseUrl + "/runs?schedule_path=" +
        encodeURIComponent(schedule_path);
      const web = new WebClient(slack.token);
    
      await web.chat.postMessage({
        channel,
        text: `Schedule ${schedule_path} failed ${
          failed_times === 1 ? "once" : (failed_times + " times")
        }`,
        blocks: [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": `Schedule <${scheduleUrl}|${schedule_path}> failed ${
                failed_times === 1 ? "once" : (failed_times + " times")
              }:\n- Script/flow: ${path}\n- Last failure: ${
                dayjs(started_at).format("DD.MM.YYYY HH:mm")
              }`,
            },
          },
        ],
        attachments: [
          {
            color: "#ff0000",
            "blocks": [{
              "type": "section",
              "text": {
                "type": "mrkdwn",
                "text": `\`\`\`\n${JSON.stringify(error, null, 2)}\n\`\`\``,
              },
            }],
          },
        ],
      });
    }
    

    Submitted by hugo697 1021 days ago