Skip to content

Commit 2776736

Browse files
committed
Apply automatic changes
1 parent c25c913 commit 2776736

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

README.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,24 @@ import (
166166
func initBpmnEngine() {
167167
bpmnEngine = bpmn_engine.New("Ordering-Microservice")
168168
process, _ = bpmnEngine.LoadFromBytes(OrderingItemsWorkflowBpmn)
169-
bpmnEngine.AddTaskHandler("validate-order", businessActionHandler)
170-
bpmnEngine.AddTaskHandler("send-bill", businessActionHandler)
171-
bpmnEngine.AddTaskHandler("send-friendly-reminder", businessActionHandler)
172-
bpmnEngine.AddTaskHandler("update-accounting", businessActionHandler)
173-
bpmnEngine.AddTaskHandler("package-and-deliver", businessActionHandler)
174-
bpmnEngine.AddTaskHandler("send-cancellation", businessActionHandler)
169+
bpmnEngine.AddTaskHandler("validate-order", printHandler)
170+
bpmnEngine.AddTaskHandler("send-bill", printHandler)
171+
bpmnEngine.AddTaskHandler("send-friendly-reminder", printHandler)
172+
bpmnEngine.AddTaskHandler("update-accounting", updateAccountingHandler)
173+
bpmnEngine.AddTaskHandler("package-and-deliver", printHandler)
174+
bpmnEngine.AddTaskHandler("send-cancellation", printHandler)
175175
}
176176

177-
func businessActionHandler(job bpmn_engine.ActivatedJob) {
177+
func printHandler(job bpmn_engine.ActivatedJob) {
178178
// do important stuff here
179-
msg := fmt.Sprintf("%s >>> Executing job '%s", time.Now(), job.ElementId)
180-
println(msg)
179+
println(fmt.Sprintf("%s >>> Executing job '%s", time.Now(), job.ElementId))
180+
job.Complete()
181+
}
182+
183+
func updateAccountingHandler(job bpmn_engine.ActivatedJob) {
184+
println(fmt.Sprintf("%s >>> Executing job '%s", time.Now(), job.ElementId))
185+
println(fmt.Sprintf("%s >>> update ledger revenue account with amount=%s", time.Now(), job.GetVariable("amount")))
186+
job.Complete()
181187
}
182188
```
183189
<!-- MARKDOWN-AUTO-DOCS:END -->
@@ -215,6 +221,8 @@ func showOrderStatus(writer http.ResponseWriter, request *http.Request) {
215221
orderId, _ := strconv.ParseInt(orderIdStr, 10, 64)
216222
instance := bpmnEngine.FindProcessInstanceById(orderId)
217223
if instance != nil {
224+
// we re-use this GET request to ensure we catch up the timers - ideally the service uses internal timers instead
225+
bpmnEngine.RunOrContinueInstance(instance.GetInstanceKey())
218226
bytes, _ := prepareJsonResponse(orderIdStr, instance.GetState(), instance.GetCreatedAt())
219227
writer.Header().Set("Content-Type", "application/json")
220228
writer.Write(bytes)
@@ -235,10 +243,25 @@ package main
235243
import (
236244
_ "embed"
237245
"net/http"
246+
"strconv"
238247
)
239248

240249
func handleReceivePayment(writer http.ResponseWriter, request *http.Request) {
241-
writer.Header().Set("Content-Type", "application/json")
250+
orderIdStr := request.FormValue("orderId")
251+
amount := request.FormValue("amount")
252+
if len(orderIdStr) > 0 && len(amount) > 0 {
253+
orderId, _ := strconv.ParseInt(orderIdStr, 10, 64)
254+
processInstance := bpmnEngine.FindProcessInstanceById(orderId)
255+
if processInstance != nil {
256+
processInstance.SetVariable("amount", amount)
257+
bpmnEngine.PublishEventForInstance(processInstance.GetInstanceKey(), "payment-received")
258+
bpmnEngine.RunOrContinueInstance(processInstance.GetInstanceKey())
259+
http.Redirect(writer, request, "/", http.StatusFound)
260+
return
261+
}
262+
}
263+
writer.WriteHeader(400)
264+
writer.Write([]byte("Bad request: the request must contain form data with 'orderId' and 'amount', and the order must exist"))
242265
}
243266
```
244267
<!-- MARKDOWN-AUTO-DOCS:END -->

0 commit comments

Comments
 (0)