Edits history of script submission #15878 for ' Signal Machine (fly)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Fly = {
      token: string;
    };
    /**
     * Signal Machine
     * Send a signal to a specific Machine within an app using the details provided in the request body.
    
     */
    export async function main(
      auth: Fly,
      app_name: string,
      machine_id: string,
      body: {
        signal?:
          | "SIGABRT"
          | "SIGALRM"
          | "SIGFPE"
          | "SIGHUP"
          | "SIGILL"
          | "SIGINT"
          | "SIGKILL"
          | "SIGPIPE"
          | "SIGQUIT"
          | "SIGSEGV"
          | "SIGTERM"
          | "SIGTRAP"
          | "SIGUSR1";
      },
    ) {
      const url = new URL(
        `https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}/signal`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago