-
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.
- Loading branch information
Showing
12 changed files
with
202 additions
and
56 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
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
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
1 change: 0 additions & 1 deletion
1
04-worker-c7spring/src/main/scala/camundala/camunda7/worker/exports.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
106 changes: 101 additions & 5 deletions
106
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 |
---|---|---|
@@ -1,12 +1,108 @@ | ||
package camundala.worker.c8zio | ||
|
||
import camundala.worker.JobWorker | ||
import camundala.domain.* | ||
import camundala.worker.{CamundalaWorkerError, JobWorker, Worker, printTimeOnConsole} | ||
import io.camunda.zeebe.client.api.response.ActivatedJob | ||
import io.camunda.zeebe.client.api.worker.{JobClient, JobHandler} | ||
import zio.* | ||
|
||
trait C8Worker extends JobWorker, JobHandler: | ||
def handle(client: JobClient, job: ActivatedJob): Unit = | ||
println(s"Handling Job: ${job}") | ||
client.newCompleteCommand(job.getKey).send().join() | ||
import java.util.Date | ||
|
||
trait C8Worker[In: InOutDecoder, Out: InOutEncoder] extends JobWorker, JobHandler: | ||
def topic: String | ||
|
||
lazy val runtime = Runtime.default | ||
|
||
import cats.data.ValidatedNel | ||
import cats.implicits.* | ||
def handle(client: JobClient, job: ActivatedJob): Unit = | ||
Unsafe.unsafe: | ||
implicit unsafe => | ||
runtime.unsafe.run( | ||
(for | ||
startDate <- ZIO.succeed(new Date()) | ||
json <- ZIO.fromEither(parser.parse(job.getVariables)) | ||
in <- ZIO.fromEither( | ||
customDecodeAccumulating[In](json.hcursor) | ||
) | ||
businessKey <- | ||
ZIO.fromEither(json.as[BusinessKey].map(_.businessKey.getOrElse("no businessKey"))) | ||
_ <- Console.printLine( | ||
s"Worker: ${job.getType} (${job.getWorker}) started > $businessKey" | ||
) | ||
_ <- Console.printLine(s"IN: $in") | ||
_ <- ZIO.attempt(client.newCompleteCommand(job.getKey).send().join()) | ||
_ <- | ||
Console.printLine( | ||
s"Worker: ${job.getType} (${job.getWorker}) ended ${printTimeOnConsole(startDate)} > $businessKey" | ||
) | ||
yield ()) | ||
).getOrThrow() | ||
|
||
def handle2(client: JobClient, job: ActivatedJob): Unit = | ||
Unsafe.unsafe { implicit unsafe => | ||
runtime.unsafe.run( | ||
for | ||
businessKey <- | ||
ZIO.succeed(Option(job.getVariable("businessKey")).getOrElse("no businessKey")) | ||
_ <- Console.printLine( | ||
s"Worker: ${job.getType} (${job.getWorker}) started > $businessKey" | ||
) | ||
json <- ZIO.fromEither(parser.parse(job.getVariables)) | ||
|
||
_ <- Console.printLine( | ||
s"Worker: ${job.getType} (${job.getWorker}) started > $businessKey" | ||
) | ||
startDate <- ZIO.succeed(new Date()) | ||
json <- ZIO.fromEither(parser.parse(job.getVariables)) | ||
_ <- Console.printLine( | ||
s"Worker: ${job.getType} (${job.getWorker}) started > $businessKey" | ||
) | ||
_ <- handleJob(client, job) | ||
_ <- | ||
Console.printLine( | ||
s"Worker: ${job.getType} (${job.getWorker}) ended ${printTimeOnConsole(startDate)} > $businessKey" | ||
) | ||
_ <- ZIO.attempt(client.newCompleteCommand(job.getKey).send().join()) | ||
yield () | ||
).getOrThrowFiberFailure() | ||
} | ||
|
||
private def handleJob( | ||
client: JobClient, | ||
job: ActivatedJob | ||
): ZIO[Any, Any, Any] = Console.printLine("handleJob") | ||
/* val variablesExtractor = ProcessVariablesExtractor(job) | ||
for | ||
tryProcessVariables <- variablesExtractor.extract(worker.variableNames ++ worker.inConfigVariableNames) | ||
tryGeneralVariables <- processExtractor.extractGeneral()) | ||
filteredOut <- worker.executor(using EngineRunContext(engineContext, tryGeneralVariables)).execute(tryProcessVariables) | ||
val tryProcessVariables = | ||
ProcessVariablesExtractor(job).extract(worker.variableNames ++ worker.inConfigVariableNames) | ||
val tryGeneralVariables = ProcessVariablesExtractor.extractGeneral() | ||
try | ||
(for | ||
generalVariables <- tryGeneralVariables | ||
context = EngineRunContext(engineContext, generalVariables) | ||
filteredOut <- | ||
worker.executor(using context).execute(tryProcessVariables) | ||
yield externalTaskService.handleSuccess(filteredOut, generalVariables.manualOutMapping) // | ||
).left.map { ex => | ||
externalTaskService.handleError(ex, tryGeneralVariables) | ||
} | ||
catch // safety net | ||
case ex: Throwable => | ||
ex.printStackTrace() | ||
externalTaskService.handleError( | ||
UnexpectedError(errorMsg = | ||
s"We caught an UnhandledException: ${ex.getMessage}\n - check the Workers Log." | ||
), | ||
tryGeneralVariables | ||
) | ||
end try | ||
end handleJob*/ | ||
case class BusinessKey(businessKey: Option[String]) | ||
object BusinessKey: | ||
given InOutCodec[BusinessKey] = deriveInOutCodec | ||
|
||
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
5 changes: 3 additions & 2 deletions
5
04-worker-c8zio/src/main/scala/camundala/worker/c8zio/C8WorkerHandler.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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package camundala.worker.c8zio | ||
package camundala.worker | ||
package c8zio | ||
|
||
/** To avoid Annotations (Camunda Version specific), we extend ExternalTaskHandler for required | ||
* parameters. | ||
*/ | ||
trait C8WorkerHandler: | ||
trait C8WorkerHandler extends WorkerHandler: | ||
|
||
|
||
end C8WorkerHandler |
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
Oops, something went wrong.