|
1 | 1 | # Workers
|
| 2 | +The implementation of an **_External Task_** is done by a _**Worker**_. |
2 | 3 |
|
| 4 | +So for each _External Task_ type we have a DSL for an according _Worker_. |
| 5 | + |
| 6 | +## Custom Worker |
| 7 | +The _Custom Worker_ is a general _Worker_ that can used for any business logic or integration. |
| 8 | + |
| 9 | +It automatically does: |
| 10 | +- validate the input variables |
| 11 | + |
| 12 | +You can create: |
| 13 | +- business logic that can't be handled by the expression language in the BPMN itself |
| 14 | +- a service integration that is not covered by the _Service Worker_ |
| 15 | +- whatever you want |
| 16 | + |
| 17 | +```scala |
| 18 | +import mycompany.myproject.bpmn.myprocess.v1.MyCustomTask.* |
| 19 | + |
| 20 | +@Configuration |
| 21 | +class MyCustomTaskWorker extends CompanyCustomWorkerDsl[In, Out]: |
| 22 | + |
| 23 | + lazy val customTask = example |
| 24 | + |
| 25 | + def runWork(in: In): Either[CamundalaWorkerError.CustomError, Out] = |
| 26 | + // your business logic |
| 27 | + ??? |
| 28 | + override def validate(in: In): Either[CamundalaWorkerError.ValidatorError, In] = |
| 29 | + ??? // custom validation logic here |
| 30 | +``` |
| 31 | +- `lazy val customTask` is just needed for the compiler to check the correctness of the types. |
| 32 | +- `runWork` is the method that is called by the _Worker_ to execute the business logic. |
| 33 | +- The code can either: |
| 34 | + - complete the task successfully with a result -> `Right[Out]` |
| 35 | + - fail the task with an error -> `Left[CamundalaWorkerError.CustomError]` |
| 36 | +- `override def validate(in: In)` is optional and can be used to add more sophisticated validation logic. |
| 37 | + If the validation fails, the process will fail. |
| 38 | + |
| 39 | +Examples: |
| 40 | + |
| 41 | +### runWork |
| 42 | +TODO |
| 43 | +### validate |
| 44 | +This is the same in every worker type. |
| 45 | +TODO |
| 46 | + |
| 47 | +```scala |
3 | 48 | ## Init Process Worker
|
| 49 | +The _Init Process Worker_ is a special _Worker_ that is used to start a process. |
| 50 | + |
| 51 | +It automatically does: |
| 52 | +- validate the input variables |
| 53 | +- merge the _inConfig_ variables with manual overrides |
| 54 | + |
| 55 | +You can: |
| 56 | +- init input process variables with default values. |
| 57 | +- init process variables used to control the process flow, |
| 58 | + like counters, variables that may not be on the process. |
| 59 | +- create simplified process variables to simplify the process flow. |
| 60 | +- validate the input variables, if you need more sophisticated validation logic, |
| 61 | + than you can do with the type definition. |
| 62 | + |
| 63 | +```scala |
| 64 | +import mycompany.myproject.bpmn.myprocess.v1.MyProcess.* |
| 65 | + |
| 66 | +@Configuration |
| 67 | +class MyProcessWorker extends CompanyInitWorkerDsl[In, Out, InitIn, InConfig]: |
| 68 | + |
| 69 | + lazy val inOutExample = example |
| 70 | + |
| 71 | + def customInit(in: In): InitIn = |
| 72 | + ??? // init logic here |
| 73 | + override def validate(in: In): Either[CamundalaWorkerError.ValidatorError, In] = |
| 74 | + ??? // custom validation logic here |
| 75 | +``` |
| 76 | +- `lazy val inOutExample` is just needed for the compiler to check the correctness of the types. |
| 77 | +- `customInit` is the method that is called by the _Worker_ to execute the init logic. |
| 78 | +- The method sets the process variables according the _InitIn_ object. |
| 79 | + Be aware that this can not fail, as the input variables are already validated. |
| 80 | +- `override def validate(in: In)` is optional and can be used to add more sophisticated validation logic. |
| 81 | + If the validation fails, the process will fail. |
| 82 | + |
| 83 | +Examples: |
| 84 | + |
| 85 | +### customInit |
4 | 86 | TODO
|
5 | 87 |
|
6 | 88 | ## Service Worker
|
7 |
| -TODO |
| 89 | +The _Service Worker_ is a special _Worker_ that is used to call a REST API service. |
8 | 90 |
|
9 |
| -## Custom Worker |
10 |
| -TODO |
| 91 | +It automatically does: |
| 92 | +- validate the input variables |
| 93 | + |
| 94 | +You can provide: |
| 95 | +- the method and the path of the service |
| 96 | +- the query parameters |
| 97 | +- the headers |
| 98 | +- the mapping of the input- or output request body |
| 99 | + |
| 100 | +```scala |
| 101 | +import mycompany.myproject.bpmn.myprocess.v1.MyServiceTask.* |
| 102 | + |
| 103 | +@Configuration |
| 104 | +class MyServiceTaskWorker extends CompanyServiceWorkerDsl[In, Out]: |
| 105 | + |
| 106 | + lazy val serviceTask = example |
| 107 | + |
| 108 | + def apiUri(in: In) = uri"$serviceBasePath/myService" |
| 109 | + override protected lazy val method: Method = Method.POST |
| 110 | + |
| 111 | + override protected def inputHeaders(in: In): Map[String, String] = |
| 112 | + ??? // map the input variables to the headers |
| 113 | + override def querySegments(in: In) = |
| 114 | + ??? // map the input variables to the query parameters |
| 115 | + override def inputMapper(in: In): Option[ServiceIn] = |
| 116 | + ??? // map the input variables to the service request body |
| 117 | + override def outputMapper( |
| 118 | + out: ServiceResponse[ServiceOut], |
| 119 | + in: In |
| 120 | + ): Either[ServiceMappingError, Out] = |
| 121 | + ??? // map the service response body and header to the output variables |
| 122 | + override def validate(in: In): Either[CamundalaWorkerError.ValidatorError, In] = |
| 123 | + ??? // custom validation logic here |
| 124 | +``` |
| 125 | +- `lazy val serviceTask` is just needed for the compiler to check the correctness of the types. |
| 126 | +- `def apiUri(in: In)` the path of the service, with the path parameters from the `in` object. |
| 127 | + The only required function. |
| 128 | +- `override protected lazy val method: Method` is the HTTP method. Default is `Method.GET`. |
| 129 | +- `override def querySegments(in: In)` is optional and can be used to add query parameters to the request. |
| 130 | +- `override def inputHeaders(in: In)` is optional and can be used to add headers to the request. |
| 131 | +- `override def inputMapper(in: In)` is optional and can be used to map the input variables to the request body. |
| 132 | +- `override def outputMapper(out: ServiceResponse[ServiceOut], in: In)` is optional and can be used to map the response body and -headers to the output variables. |
| 133 | +- `override def validate(in: In)` is optional and can be used to add more sophisticated validation logic. |
| 134 | + If the validation fails, the process will fail. |
| 135 | + |
| 136 | +Examples: |
| 137 | + |
| 138 | +### apiUri |
| 139 | +TODO |
| 140 | +### querySegments |
| 141 | +TODO |
| 142 | +### inputHeaders |
| 143 | +TODO |
| 144 | +### inputMapper |
| 145 | +TODO |
| 146 | +### outputMapper |
0 commit comments