Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created March 4, 2022 06:12
Show Gist options
  • Save percybolmer/67119ae792a11025be9c2a8dd37a7add to your computer and use it in GitHub Desktop.
Save percybolmer/67119ae792a11025be9c2a8dd37a7add to your computer and use it in GitHub Desktop.
Cadence handler for sending signal
// Order is used to send a signal to the worker
func (cc *CadenceClient) Order(w http.ResponseWriter, r *http.Request) {
// Grab order info from body
var orderInfo orders.Order
err := json.NewDecoder(r.Body).Decode(&orderInfo)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
log.Print(orderInfo)
// Send a signal to the Workflow
// We need to provide a Workflow ID, the RUN ID of the workflow, and the Signal type
err = cc.client.SignalWorkflow(r.Context(), cc.orderWorkflowID, cc.orderWorkflowRunID, "order", orderInfo)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
log.Println("Signalled system of order")
w.WriteHeader(http.StatusOK)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment