Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timer issue #2

Merged
merged 2 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 78 additions & 59 deletions DictatorBot.bpmn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" id="Definitions_1efsd93" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.6.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1efsd93" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.6.0" camunda:diagramRelationId="53baf7fe-6917-4430-a04b-7a606d5a7020">
<bpmn:process id="DictatorBot" name="DictatorBot" isExecutable="true">
<bpmn:sequenceFlow id="Flow_0q8rhw9" name="Message" sourceRef="StartEvent_1" targetRef="Activity_08wqhhy" />
<bpmn:exclusiveGateway id="user_auth" name="User Auth">
Expand Down Expand Up @@ -80,6 +80,7 @@
</bpmn:serviceTask>
<bpmn:serviceTask id="Activity_1cuby9c" name="update on-call" camunda:type="external" camunda:topic="update_oncall">
<bpmn:incoming>Flow_1b4al5q</bpmn:incoming>
<bpmn:incoming>Flow_15f58zb</bpmn:incoming>
<bpmn:outgoing>Flow_0gayirk</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1hw99aj" sourceRef="task_type" targetRef="Activity_17tqrr2">
Expand Down Expand Up @@ -118,11 +119,55 @@
<bpmn:incoming>Flow_1cx5s83</bpmn:incoming>
<bpmn:outgoing>Flow_0mfnkj9</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:startEvent id="timer_update" name="Auto Dictator">
<bpmn:outgoing>Flow_15f58zb</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_1fcgpzb">
<bpmn:timeCycle xsi:type="bpmn:tFormalExpression">0 12 * * 1 ?</bpmn:timeCycle>
</bpmn:timerEventDefinition>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_15f58zb" sourceRef="timer_update" targetRef="Activity_1cuby9c" />
</bpmn:process>
<bpmn:message id="Message_1uyfizy" name="Query_dictator" />
<bpmn:message id="Message_08dzuqp" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DictatorBot">
<bpmndi:BPMNEdge id="Flow_15f58zb_di" bpmnElement="Flow_15f58zb">
<di:waypoint x="198" y="990" />
<di:waypoint x="1150" y="990" />
<di:waypoint x="1150" y="750" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0mfnkj9_di" bpmnElement="Flow_0mfnkj9">
<di:waypoint x="1070" y="120" />
<di:waypoint x="1390" y="120" />
<di:waypoint x="1390" y="800" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1cx5s83_di" bpmnElement="Flow_1cx5s83">
<di:waypoint x="460" y="465" />
<di:waypoint x="460" y="120" />
<di:waypoint x="970" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ppohai_di" bpmnElement="Flow_0ppohai">
<di:waypoint x="485" y="490" />
<di:waypoint x="565" y="490" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0f5h5pg_di" bpmnElement="Flow_0f5h5pg">
<di:waypoint x="1060" y="270" />
<di:waypoint x="1370" y="270" />
<di:waypoint x="1370" y="800" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1di8ity_di" bpmnElement="get_help" bioc:stroke="#000" bioc:fill="#fff">
<di:waypoint x="460" y="460" />
<di:waypoint x="460" y="270" />
<di:waypoint x="960" y="270" />
<bpmndi:BPMNLabel>
<dc:Bounds x="453" y="362" width="44" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0gayirk_di" bpmnElement="Flow_0gayirk">
<di:waypoint x="1180" y="750" />
<di:waypoint x="1180" y="820" />
<di:waypoint x="1300" y="820" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1xbz8ic_di" bpmnElement="Flow_1xbz8ic">
<di:waypoint x="1060" y="390" />
<di:waypoint x="1350" y="390" />
Expand Down Expand Up @@ -215,101 +260,75 @@
<dc:Bounds x="230" y="472" width="45" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0gayirk_di" bpmnElement="Flow_0gayirk">
<di:waypoint x="1180" y="750" />
<di:waypoint x="1180" y="820" />
<di:waypoint x="1300" y="820" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1di8ity_di" bpmnElement="get_help" bioc:stroke="#000" bioc:fill="#fff">
<di:waypoint x="460" y="460" />
<di:waypoint x="460" y="270" />
<di:waypoint x="960" y="270" />
<bpmndi:BPMNShape id="Gateway_0p7zuno_di" bpmnElement="user_auth" isMarkerVisible="true" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="565" y="465" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="453" y="362" width="44" height="14" />
<dc:Bounds x="566" y="435" width="49" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0f5h5pg_di" bpmnElement="Flow_0f5h5pg">
<di:waypoint x="1060" y="270" />
<di:waypoint x="1370" y="270" />
<di:waypoint x="1370" y="800" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ppohai_di" bpmnElement="Flow_0ppohai">
<di:waypoint x="485" y="490" />
<di:waypoint x="565" y="490" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1cx5s83_di" bpmnElement="Flow_1cx5s83">
<di:waypoint x="460" y="465" />
<di:waypoint x="460" y="120" />
<di:waypoint x="970" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0mfnkj9_di" bpmnElement="Flow_0mfnkj9">
<di:waypoint x="1070" y="120" />
<di:waypoint x="1390" y="120" />
<di:waypoint x="1390" y="800" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1cibw1h_di" bpmnElement="Event_1cibw1h" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="1762" y="472" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1757" y="515" width="48" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0mqu5cr_di" bpmnElement="on-call-check" isMarkerVisible="true" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="1025" y="685" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1015" y="655" width="71" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1f1raod_di" bpmnElement="task_type" isMarkerVisible="true" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="755" y="465" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="796.5" y="463" width="45" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1fc9dk3_di" bpmnElement="Activity_08wqhhy">
<dc:Bounds x="270" y="450" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_03tl98n_di" bpmnElement="Activity_0am1dt5">
<dc:Bounds x="840" y="670" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0hylgwo_di" bpmnElement="send_message">
<dc:Bounds x="1480" y="450" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1q9csis_di" bpmnElement="format_message">
<dc:Bounds x="1300" y="800" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0z0sdf5_di" bpmnElement="Activity_1cuby9c">
<dc:Bounds x="1130" y="670" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_0b6tco1_di" bpmnElement="Activity_11xn5ao">
<dc:Bounds x="960" y="450" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1phujcz_di" bpmnElement="Activity_0a9dyzq">
<dc:Bounds x="960" y="550" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0b6tco1_di" bpmnElement="Activity_11xn5ao">
<dc:Bounds x="960" y="450" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_0z0sdf5_di" bpmnElement="Activity_1cuby9c">
<dc:Bounds x="1130" y="670" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0tpfksy_di" bpmnElement="Activity_17tqrr2">
<dc:Bounds x="960" y="350" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1f1raod_di" bpmnElement="task_type" isMarkerVisible="true" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="755" y="465" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="796.5" y="463" width="45" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1fc9dk3_di" bpmnElement="Activity_08wqhhy">
<dc:Bounds x="270" y="450" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0nxl4f6_di" bpmnElement="StartEvent_1" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="162" y="472" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="157" y="515" width="46" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1cibw1h_di" bpmnElement="Event_1cibw1h" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="1762" y="472" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1757" y="515" width="48" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0hylgwo_di" bpmnElement="send_message">
<dc:Bounds x="1480" y="450" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_06e4c44_di" bpmnElement="Activity_0pulv84">
<dc:Bounds x="960" y="230" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0p7zuno_di" bpmnElement="user_auth" isMarkerVisible="true" bioc:stroke="#000" bioc:fill="#fff">
<dc:Bounds x="565" y="465" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="566" y="435" width="49" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0u1o14q_di" bpmnElement="Gateway_0u1o14q" isMarkerVisible="true">
<dc:Bounds x="435" y="465" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1j4ymdw_di" bpmnElement="getAuthorized">
<dc:Bounds x="970" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ki7etm_di" bpmnElement="timer_update">
<dc:Bounds x="162" y="972" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="149" y="1015" width="64" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
61 changes: 37 additions & 24 deletions dictator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"},
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down