-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version with Worker for Camunda8.
- Loading branch information
Showing
15 changed files
with
261 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package camundala.worker | ||
|
||
|
||
import scala.concurrent.duration.* | ||
|
||
|
||
trait JobWorker: | ||
def topic: String | ||
def timeout: Duration = 10.seconds | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package camundala.worker | ||
|
||
import zio.* | ||
|
||
import scala.compiletime.uninitialized | ||
|
||
trait WorkerApp extends ZIOAppDefault: | ||
def workerClients: Seq[WorkerClient[?]] | ||
var theWorkers: Set[JobWorker] = uninitialized | ||
|
||
def workers(dWorkers: (JobWorker | Seq[JobWorker])*): Unit = | ||
theWorkers = dWorkers | ||
.flatMap: | ||
case d: JobWorker => Seq(d) | ||
case s: Seq[?] => s.collect{case d: JobWorker => d} | ||
.toSet | ||
|
||
override def run: ZIO[Any, Any, Any] = | ||
for | ||
_ <- Console.printLine("Starting WorkerApp") | ||
_ <- ZIO.collectAllPar(workerClients.map(_.run(theWorkers))) | ||
yield () |
10 changes: 10 additions & 0 deletions
10
03-worker/src/main/scala/camundala/worker/WorkerClient.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package camundala.worker | ||
|
||
import camundala.worker.JobWorker | ||
import zio.ZIO | ||
|
||
trait WorkerClient[T <: JobWorker]: | ||
def run(workers: Set[JobWorker]): ZIO[Any, Any, Any] = | ||
runWorkers(workers.collect { case w: T => w }) | ||
protected def runWorkers(workers: Set[T]): ZIO[Any, Any, Any] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
04-worker-c8zio/src/main/scala/camundala/worker/c8zio/C8Worker.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package camundala.worker.c8zio | ||
|
||
import camundala.worker.JobWorker | ||
import io.camunda.zeebe.client.api.response.ActivatedJob | ||
import io.camunda.zeebe.client.api.worker.{JobClient, JobHandler} | ||
|
||
trait C8Worker extends JobWorker, JobHandler: | ||
def handle(client: JobClient, job: ActivatedJob): Unit = | ||
println(s"Handling Job: ${job}") | ||
client.newCompleteCommand(job.getKey).send().join() | ||
|
||
end C8Worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
04-worker-c8zio/src/main/scala/camundala/worker/c8zio/ExampleJobHandler.scala
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
05-examples/demos/03-worker/src/main/resources/twitter-auto-c7.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0m1f84q" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.21.0"> | ||
<bpmn:process id="twitter-auto-c7" name="twitter-auto-c7" isExecutable="true"> | ||
<bpmn:startEvent id="StartEvent_1"> | ||
<bpmn:outgoing>Flow_1c8rqmn</bpmn:outgoing> | ||
</bpmn:startEvent> | ||
<bpmn:sequenceFlow id="Flow_1c8rqmn" sourceRef="StartEvent_1" targetRef="Activity_1p8rmh1" /> | ||
<bpmn:endEvent id="Event_1mv5kky"> | ||
<bpmn:incoming>Flow_0yzjas8</bpmn:incoming> | ||
</bpmn:endEvent> | ||
<bpmn:sequenceFlow id="Flow_0yzjas8" sourceRef="Activity_1p8rmh1" targetRef="Event_1mv5kky" /> | ||
<bpmn:serviceTask id="Activity_1p8rmh1" name="Publish on Twitter" camunda:type="external" camunda:topic="publish-tweet"> | ||
<bpmn:incoming>Flow_1c8rqmn</bpmn:incoming> | ||
<bpmn:outgoing>Flow_0yzjas8</bpmn:outgoing> | ||
</bpmn:serviceTask> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="twitter-auto-c7"> | ||
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> | ||
<dc:Bounds x="179" y="99" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Event_1mv5kky_di" bpmnElement="Event_1mv5kky"> | ||
<dc:Bounds x="432" y="99" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Activity_1iubci5_di" bpmnElement="Activity_1p8rmh1"> | ||
<dc:Bounds x="270" y="77" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNEdge id="Flow_1c8rqmn_di" bpmnElement="Flow_1c8rqmn"> | ||
<di:waypoint x="215" y="117" /> | ||
<di:waypoint x="270" y="117" /> | ||
</bpmndi:BPMNEdge> | ||
<bpmndi:BPMNEdge id="Flow_0yzjas8_di" bpmnElement="Flow_0yzjas8"> | ||
<di:waypoint x="370" y="117" /> | ||
<di:waypoint x="432" y="117" /> | ||
</bpmndi:BPMNEdge> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |
16 changes: 16 additions & 0 deletions
16
...es/demos/03-worker/src/main/scala/camundala/examples/demos/newWorker/CompanyBpmnDsl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package camundala.examples.demos.newWorker | ||
|
||
import camundala.bpmn.* | ||
|
||
trait CompanyBpmnDsl extends BpmnDsl: | ||
|
||
end CompanyBpmnDsl | ||
|
||
trait CompanyBpmnProcessDsl extends BpmnProcessDsl, CompanyBpmnDsl | ||
trait CompanyBpmnServiceTaskDsl extends BpmnServiceTaskDsl, CompanyBpmnDsl | ||
trait CompanyBpmnCustomTaskDsl extends BpmnCustomTaskDsl, CompanyBpmnDsl | ||
trait CompanyBpmnDecisionDsl extends BpmnDecisionDsl, CompanyBpmnDsl | ||
trait CompanyBpmnUserTaskDsl extends BpmnUserTaskDsl, CompanyBpmnDsl | ||
trait CompanyBpmnMessageEventDsl extends BpmnMessageEventDsl, CompanyBpmnDsl | ||
trait CompanyBpmnSignalEventDsl extends BpmnSignalEventDsl, CompanyBpmnDsl | ||
trait CompanyBpmnTimerEventDsl extends BpmnTimerEventDsl, CompanyBpmnDsl |
34 changes: 34 additions & 0 deletions
34
...os/03-worker/src/main/scala/camundala/examples/demos/newWorker/CompanyWorkerHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package camundala.examples.demos.newWorker | ||
|
||
import camundala.camunda7.worker.C7WorkerHandler | ||
import camundala.domain.* | ||
import camundala.worker.* | ||
import camundala.worker.c8zio.C8Worker | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait CompanyWorkerHandler extends C7WorkerHandler, C8Worker | ||
|
||
trait CompanyValidationWorkerDsl[ | ||
In <: Product: InOutCodec | ||
] extends CompanyWorkerHandler, ValidationWorkerDsl[In] | ||
|
||
trait CompanyInitWorkerDsl[ | ||
In <: Product: InOutCodec, | ||
Out <: Product: InOutCodec, | ||
InitIn <: Product: InOutCodec, | ||
InConfig <: Product: InOutCodec | ||
] extends CompanyWorkerHandler, InitWorkerDsl[In, Out, InitIn, InConfig] | ||
|
||
trait CompanyCustomWorkerDsl[ | ||
In <: Product: InOutCodec, | ||
Out <: Product: InOutCodec | ||
] extends CompanyWorkerHandler, CustomWorkerDsl[In, Out] | ||
|
||
|
||
trait CompanyServiceWorkerDsl[ | ||
In <: Product: InOutCodec, | ||
Out <: Product: InOutCodec, | ||
ServiceIn: InOutEncoder, | ||
ServiceOut: InOutDecoder: ClassTag | ||
] extends CompanyWorkerHandler, ServiceWorkerDsl[In, Out, ServiceIn, ServiceOut] |
40 changes: 40 additions & 0 deletions
40
...demos/03-worker/src/main/scala/camundala/examples/demos/newWorker/ExampleJobHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package camundala.examples.demos.newWorker | ||
|
||
import camundala.bpmn.CustomTask | ||
import camundala.domain.* | ||
import camundala.examples.demos.newWorker.ExampleJob.* | ||
import camundala.worker.CamundalaWorkerError | ||
import camundala.worker.c8zio.C8Worker | ||
|
||
object ExampleJobHandler extends CompanyCustomWorkerDsl[In, Out]: | ||
lazy val customTask = example | ||
def runWork(in: In): Either[CamundalaWorkerError.CustomError, Out] = ??? | ||
end ExampleJobHandler | ||
|
||
object ExampleJob extends CompanyBpmnCustomTaskDsl: | ||
|
||
val topicName = "publish-tweet" | ||
val descr: String = "Creates and adjusts variables for the module creditcard." | ||
|
||
case class In( | ||
myId: Long = 123L, | ||
myMessage: String = "hello" | ||
) | ||
|
||
object In: | ||
given ApiSchema[In] = deriveApiSchema | ||
given InOutCodec[In] = deriveInOutCodec | ||
|
||
case class Out( | ||
myId: Long = 123L, | ||
myMessage: String = "hello" | ||
) | ||
object Out: | ||
given ApiSchema[Out] = deriveApiSchema | ||
given InOutCodec[Out] = deriveInOutCodec | ||
|
||
lazy val example = customTask( | ||
In(), | ||
Out() | ||
) | ||
end ExampleJob |
16 changes: 16 additions & 0 deletions
16
...les/demos/03-worker/src/main/scala/camundala/examples/demos/newWorker/TestWorkerApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package camundala.examples.demos.newWorker | ||
|
||
import camundala.worker.{WorkerApp, WorkerClient} | ||
import camundala.worker.c8zio.C8WorkerClient | ||
|
||
trait CompanyWorkerApp extends WorkerApp: | ||
lazy val workerClients: Seq[WorkerClient[?]] = | ||
Seq(C8WorkerClient) | ||
|
||
|
||
object TestWorkerApp extends CompanyWorkerApp: | ||
workers( | ||
ExampleJobHandler | ||
) | ||
|
||
|
Oops, something went wrong.