From 42862cecaa33a0af88a462cd50731cecbdcb61d0 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Tue, 30 Mar 2021 11:28:33 -0400 Subject: [PATCH 1/2] Fixed the issue with the timer from Camunda, so no more cron job! --- dictator.go | 61 ++++++++++++++++++++++++++++++++--------------------- go.mod | 3 +-- go.sum | 6 ++---- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/dictator.go b/dictator.go index a64c6dc..5216039 100644 --- a/dictator.go +++ b/dictator.go @@ -18,9 +18,9 @@ import ( "syscall" "time" - camundaclientgo "github.com/citilinkru/camunda-client-go" - "github.com/citilinkru/camunda-client-go/processor" - "github.com/robfig/cron/v3" + camundaclientgo "github.com/citilinkru/camunda-client-go/v2" + "github.com/citilinkru/camunda-client-go/v2/processor" + // "github.com/robfig/cron/v3" "gopkg.in/yaml.v2" ) @@ -229,14 +229,19 @@ func validateDictator(newVars map[string]camundaclientgo.Variable, contx *proces func startCamundaProcess(data DictatorPayload) { - client := camundaclientgo.NewClient(camundaclientgo.ClientOptions{ - // this should use values from the config file - EndpointUrl: config.CamundaHost[0].Protocol + "://" + config.CamundaHost[0].Host + ":" + fmt.Sprint(config.CamundaHost[0].Port) + "/engine-rest", //"https://davidgs.com:8443/engine-rest", - ApiUser: "demo", - ApiPassword: "demo", - Timeout: time.Second * 10, - }) - + opts := camundaclientgo.ClientOptions{} + opts.ApiPassword = "demo" + opts.ApiUser = "demo" + opts.EndpointUrl = config.CamundaHost[0].Protocol + "://" + config.CamundaHost[0].Host + ":" + fmt.Sprint(config.CamundaHost[0].Port) + "/engine-rest" + + // camundaclientgo.ClientOptions{ + // // this should use values from the config file + // EndpointUrl: config.CamundaHost[0].Protocol + "://" + config.CamundaHost[0].Host + ":" + fmt.Sprint(config.CamundaHost[0].Port) + "/engine-rest", //"https://davidgs.com:8443/engine-rest", + // ApiUser: "demo", + // ApiPassword: "demo", + // Timeout: time.Second * 10, + // }) + messageName := "Query_dictator" processKey := "DictatorBot" variables := map[string]camundaclientgo.Variable{ "command": {Value: strings.TrimSpace(data.Command), Type: "string"}, @@ -248,10 +253,17 @@ func startCamundaProcess(data DictatorPayload) { "user_id": {Value: data.UserID, Type: "string"}, "api_app_id": {Value: data.APIAppID, Type: "string"}, } - _, err := client.ProcessDefinition.StartInstance( - camundaclientgo.QueryProcessDefinitionBy{Key: &processKey}, - camundaclientgo.ReqStartInstance{Variables: &variables}, - ) + client := camundaclientgo.NewClient(opts) + reqMessage := camundaclientgo.ReqMessage{} + reqMessage.MessageName = messageName + reqMessage.BusinessKey = processKey + reqMessage.ProcessVariables = &variables + err := client.Message.SendMessage(&reqMessage) + + // _, err := client.ProcessDefinition.StartInstance( + // camundaclientgo.QueryProcessDefinitionBy{Key: &processKey}, + // camundaclientgo.ReqStartInstance{Variables: &variables}, + // ) if err != nil { log.Printf("Error starting process: %s\n", err) return @@ -261,7 +273,7 @@ func startCamundaProcess(data DictatorPayload) { // Handles all the incomming https requests func dictator(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { - log.Println("GET Method Not Supported") + // log.Println("GET Method Not Supported") http.Error(w, "GET Method not supported", 400) } else { key := r.Header.Get("X-Slack-Signature") @@ -288,7 +300,7 @@ func dictator(w http.ResponseWriter, r *http.Request) { w.WriteHeader(400) return } - log.Println(t.Command) + // log.Println(t.Command) w.WriteHeader(200) startCamundaProcess(t) } @@ -329,11 +341,11 @@ func main() { WriteDictator() os.Exit(1) }() - cro := cron.New() - cro.AddFunc("0 12 * * MON", func() { - RunEverySecond() - }) - cro.Start() + // cro := cron.New() + // cro.AddFunc("0 12 * * MON", func() { + // RunEverySecond() + // }) + // cro.Start() client := camundaclientgo.NewClient(camundaclientgo.ClientOptions{ EndpointUrl: config.CamundaHost[0].Protocol + "://" + config.CamundaHost[0].Host + ":" + fmt.Sprint(config.CamundaHost[0].Port) + "/engine-rest", @@ -370,7 +382,6 @@ func main() { // fmt.Printf("Running task %s. WorkerId: %s. TopicName: %s\n", ctx.Task.Id, ctx.Task.WorkerId, ctx.Task.TopicName) vars := make(map[string]camundaclientgo.Variable) - vars["message_type"] = camundaclientgo.Variable{Value: "success", Type: "string"} vars["message"] = camundaclientgo.Variable{Value: getDictatorString(), Type: "string"} err := ctx.Complete(processor.QueryComplete{ @@ -510,7 +521,7 @@ func main() { timer = "timer" } if timer == "timer" { - fmt.Println("Timer event fired!") + // fmt.Println("Timer event fired!") vars := make(map[string]camundaclientgo.Variable) lastTater := getOnCall() if config.OnCallIndex+1 >= len(getRotation()) { @@ -536,6 +547,8 @@ func main() { return nil } else { text := fmt.Sprintf("%v", varb["command"].Value) + fmt.Printf("Get Auth: %v\n", varb["command"].Value) + newTater, err := url.QueryUnescape(text) if err != nil { WriteDictator() diff --git a/go.mod b/go.mod index eac9738..a610652 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module camunda.com/dicator go 1.16 require ( - github.com/citilinkru/camunda-client-go v1.1.2 - github.com/robfig/cron/v3 v3.0.1 + github.com/citilinkru/camunda-client-go/v2 v2.1.1 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 4727f17..d983871 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ -github.com/citilinkru/camunda-client-go v1.1.2 h1:k4uKGwWkrZngYnXQt/DkLWSrZZESNJC7pEgWoTajM3k= -github.com/citilinkru/camunda-client-go v1.1.2/go.mod h1:zYM6H5ap6DPux11lSpW6EwapKrBSGfHMxb+7btUIY4w= -github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= -github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= +github.com/citilinkru/camunda-client-go/v2 v2.1.1 h1:Ji1e0IcJ4pFYtD0RbcIu4fkmssUE2A7V9paEqy5PWDY= +github.com/citilinkru/camunda-client-go/v2 v2.1.1/go.mod h1:rBdmDrRvbL+CcY87uDLsbumuzHnWOPsJdOGJ5oWwcAU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= From 8d2319fac56a3c54805d47d24424f8c2b7c96c8e Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Tue, 30 Mar 2021 11:32:30 -0400 Subject: [PATCH 2/2] Added new BPMN --- DictatorBot.bpmn | 137 +++++++++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 59 deletions(-) diff --git a/DictatorBot.bpmn b/DictatorBot.bpmn index 87745e0..6d3ea9b 100644 --- a/DictatorBot.bpmn +++ b/DictatorBot.bpmn @@ -1,5 +1,5 @@ - + @@ -80,6 +80,7 @@ Flow_1b4al5q + Flow_15f58zb Flow_0gayirk @@ -118,11 +119,55 @@ Flow_1cx5s83 Flow_0mfnkj9 + + Flow_15f58zb + + 0 12 * * 1 ? + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -215,101 +260,75 @@ - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + +