Created
March 4, 2022 06:12
-
-
Save percybolmer/67119ae792a11025be9c2a8dd37a7add to your computer and use it in GitHub Desktop.
Cadence handler for sending signal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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