Skip to content

Commit

Permalink
Implemented minimal functional
Browse files Browse the repository at this point in the history
  • Loading branch information
liderman committed Apr 21, 2019
1 parent b018718 commit 34341b8
Show file tree
Hide file tree
Showing 13 changed files with 1,956 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: go

go:
- 1.8
- 1.9
- 1.10
- 1.11
- 1.12
- tip

git:
depth: 1

before_script:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint

script:
- golangci-lint run
- go test -v -race ./...
140 changes: 140 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Camunda REST API client for golang
[![Build Status](https://travis-ci.org/citilinkru/camunda-client-go.svg?branch=master)](https://travis-ci.org/citilinkru/camunda-client-go) [![GoDoc](https://godoc.org/github.com/citilinkru/camunda-client-go?status.svg)](https://godoc.org/github.com/citilinkru/camunda-client-go)

Installation
-----------
go get github.com/citilinkru/camunda-client-go

Usage
-----------

Create client:
```go
timeout := time.Second * 10
client := camunda_client_go.NewClient(camunda_client_go.ClientOptions{
ApiUser: "demo",
ApiPassword: "demo",
Timeout: &timeout,
})
```

Create deployment:
```go
file, err := os.Open("demo.bpmn")
if err != nil {
logger.Errorf("Error read file: %s", err)
return
}
result, err = client.Deployment.Create(camunda_client_go.ReqDeploymentCreate{
DeploymentName: "DemoProcess",
Resources: map[string]interface{}{
"demo.bpmn": file,
},
})
if err != nil {
logger.Errorf("Error deploy process: %s", err)
return
}

logger.infof("Result: %#+v", result)
```

Start instance:
```go
processKey := "DemoProcess"
result, err = client.ProcessDefinition.StartInstance(
camunda_client_go.QueryProcessDefinitionBy{Key: &processKey},
camunda_client_go.ReqStartInstance{},
)
if err != nil {
logger.Errorf("Error start process: %s", err)
return
}

logger.infof("Result: %#+v", result)
```


Usage for External task
-----------

Create external task processor:
```go
logger := logrus.New()
asyncResponseTimeout := 5000
proc := processor.NewProcessor(client, &processor.ProcessorOptions{
WorkerId: "demo-worker",
LockDuration: time.Second * 5,
MaxTasks: 1,
AsyncResponseTimeout: &asyncResponseTimeout,
}, logger)
```

Add and subscribe external task handler:
```go
proc.AddHandler(
&[]camunda_client_go.QueryFetchAndLockTopic{
{TopicName: "HelloWorldSetter"},
},
func(ctx *processor.Context) error {
logger.Infof("Running task %s. WorkerId: %s. TopicName: %s", ctx.Task.Id, ctx.Task.WorkerId, ctx.Task.TopicName)

err := ctx.Complete(processor.QueryComplete{
Variables: &map[string]camunda_client_go.Variable {
"result": {Value: "Hello world!", Type: "string"},
},
})
if err != nil {
logger.Errorf("Error set complete task %s: %s", ctx.Task.Id, err)

return ctx.HandleFailure(processor.QueryHandleFailure{
ErrorMessage: &errTxt,
Retries: &retries,
RetryTimeout: &retryTimeout,
})
}

logger.Infof("Task %s completed", ctx.Task.Id)
return nil
},
)
```

WARNING
-----------
**This project is still under development. Use code with caution!**

Features
-----------

* Support api version `7.11`
* Full support API `External Task`
* Full support API `Process Definition`
* Full support API `Deployment`
* Without external dependencies

Road map
-----------

* Full coverage by tests
* Full support references api

Testing
-----------
Unit-tests:
```bash
go test -v -race ./...
```

Run linter:
```bash
golangci-lint run
```

LICENSE
-----------
MIT

AUTHOR
-----------
Konstantin Osipov <k.osipov.msk@gmail.com>
23 changes: 23 additions & 0 deletions case-definition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package camunda_client_go

// ResCaseDefinition a JSON object corresponding to the CaseDefinition interface in the engine
type ResCaseDefinition struct {
// The id of the case definition
Id string `json:"id"`
// The key of the case definition, i.e., the id of the CMMN 2.0 XML case definition
Key string `json:"key"`
// The category of the case definition
Category string `json:"category"`
// The name of the case definition
Name string `json:"name"`
// The version of the case definition that the engine assigned to it
Version int `json:"Version"`
// The file name of the case definition
Resource string `json:"resource"`
// The deployment id of the case definition
DeploymentId string `json:"deploymentId"`
// The tenant id of the case definition
TenantId string `json:"tenantId"`
// History time to live value of the case definition. Is used within History cleanup
HistoryTimeToLive int `json:"historyTimeToLive"`
}
Loading

0 comments on commit 34341b8

Please sign in to comment.