From c890897687ca8318bcb417850370077a38b51321 Mon Sep 17 00:00:00 2001 From: William Yang Date: Thu, 25 Jun 2026 22:42:11 -0400 Subject: [PATCH 1/2] feat: add --discord webhook channel to subscription command --- internal/cmd/subscription.go | 37 +++++++++++++++++++-------- internal/subscription/subscription.go | 23 ++++++++++------- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/internal/cmd/subscription.go b/internal/cmd/subscription.go index 98a824b..2e0394c 100644 --- a/internal/cmd/subscription.go +++ b/internal/cmd/subscription.go @@ -1,33 +1,50 @@ package cmd -import ( +import ( "fmt" + "github.com/spf13/cobra" "watcloud-cli/internal/subscription" ) +var discordWebhook string + var subscriptionCmd = &cobra.Command{ Use: "subscription [job_id] [email]", - Short: "Get an email notification when a SLURM job finishes", - Long: "Subscribe to a specific SLURM job by its ID. When the job completes, you will receive an email notification.", - - Args: cobra.ExactArgs(2), + Short: "Get notified when a SLURM job finishes", + Long: "Subscribe to a specific SLURM job by its ID. When the job completes you will be " + + "notified by email, or on Discord with --discord .", + + Args: cobra.RangeArgs(1, 2), Run: func(cmd *cobra.Command, args []string) { jobID := args[0] - email := args[1] - fmt.Printf("Attempting to subscribe %s to job %s...\n", email, jobID) - err := subscription.SubscribeToJobAPI(jobID, email) + var channel, target string + switch { + case discordWebhook != "": + channel = "discord" + target = discordWebhook + case len(args) == 2: + channel = "email" + target = args[1] + default: + fmt.Println("Error: provide an email address or use --discord ") + return + } + + fmt.Printf("Attempting to subscribe job %s (%s)...\n", jobID, channel) + err := subscription.SubscribeToJobAPI(jobID, target, channel) if err != nil { fmt.Printf("Failed to subscribe to job: %v\n", err) - } else { - fmt.Printf("Success! %s You will be emailed when job %s completes \n", email, jobID) + } else { + fmt.Printf("Success! You will be notified via %s when job %s completes.\n", channel, jobID) } }, } func init() { + subscriptionCmd.Flags().StringVar(&discordWebhook, "discord", "", "Discord webhook URL to notify instead of email") rootCmd.AddCommand(subscriptionCmd) } diff --git a/internal/subscription/subscription.go b/internal/subscription/subscription.go index a0bb2df..73537fa 100644 --- a/internal/subscription/subscription.go +++ b/internal/subscription/subscription.go @@ -9,16 +9,21 @@ import ( ) type JobSubscriptionData struct { - JobID string `json:"job_id"` - Email string `json:"email"` + JobID string `json:"job_id"` + Channel string `json:"channel"` + Target string `json:"target"` } -func SubscribeToJobAPI(jobID string, email string) error { - +// SubscribeToJobAPI registers a subscription so the user is notified when the +// SLURM job finishes. channel is "email" or "discord"; target is the email +// address or the Discord webhook URL respectively. +func SubscribeToJobAPI(jobID string, target string, channel string) error { + // Create data package payload := JobSubscriptionData{ - JobID: jobID, - Email: email, + JobID: jobID, + Channel: channel, + Target: target, } jsonData, err := json.Marshal(payload) @@ -32,7 +37,7 @@ func SubscribeToJobAPI(jobID string, email string) error { if err != nil { return fmt.Errorf("failed to create request: %v", err) } - + req.Host = "slurm-email-monitor.cluster.watonomous.ca" req.Header.Set("Content-Type", "application/json") @@ -41,7 +46,7 @@ func SubscribeToJobAPI(jobID string, email string) error { if err != nil { return fmt.Errorf("network error: %v", err) } - + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { @@ -49,4 +54,4 @@ func SubscribeToJobAPI(jobID string, email string) error { } return nil -} \ No newline at end of file +} From 4bd89934bde43fcbbda17da16af7c38347f2f404 Mon Sep 17 00:00:00 2001 From: William Yang Date: Thu, 25 Jun 2026 23:17:08 -0400 Subject: [PATCH 2/2] docs: document watcloud subscription command and --discord option --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 19f1adf..0e8400a 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,17 @@ Run: | start/run | Starts the rootless Docker Daemon. | | status | Lists all non-interactive background user processes (daemons). | +### watcloud subscription [email] + +Get notified when a SLURM job finishes. + +| Usage | Description | +|-------|-------------| +| `watcloud subscription ` | Email notification when the job completes | +| `watcloud subscription --discord ` | Discord notification via a webhook URL | + +To get a Discord webhook URL, in your Discord channel: **Edit Channel → Integrations → Webhooks → New Webhook → Copy Webhook URL**. + --- For help and usage examples, run: