@@ -4,10 +4,7 @@ import org.camunda.worker.akka.client.LockedTask
4
4
import org .camunda .worker .akka .PollActor ._
5
5
import akka .routing ._
6
6
import akka .actor .Props
7
- import scala .concurrent ._
8
- import ExecutionContext .Implicits .global
9
7
import org .camunda .worker .akka .client .VariableValue
10
- import org .camunda .worker .akka .client .VariableValue .anyToVariableValue
11
8
import org .camunda .worker .akka .Worker
12
9
import scala .concurrent .duration ._
13
10
import scala .util .Random
@@ -17,14 +14,19 @@ import scala.util.Random
17
14
*/
18
15
class PaymentWorker (delay : Duration ) extends Worker {
19
16
20
- def work (task : LockedTask ): Future [ Map [String , VariableValue ]] = Future {
17
+ def work (task : LockedTask ): Map [String , VariableValue ] = {
21
18
22
- val payment = calculatePayment
19
+ val orderId = task.variables.get(" orderId" ) match {
20
+ case Some (variableValue) => variableValue.asValue[String ]
21
+ case None => " " // throw IllegalArgumentException("no order id available")
22
+ }
23
23
24
- Map (" payment" -> payment)
24
+ val payment = calculatePayment(orderId)
25
+
26
+ Map (s " payment- $orderId" -> payment)
25
27
}
26
28
27
- private def calculatePayment = {
29
+ private def calculatePayment ( orderId : String ) = {
28
30
// simulate calculation
29
31
java.lang.Thread .sleep(delay.toMillis)
30
32
// return result
@@ -35,7 +37,7 @@ class PaymentWorker(delay: Duration) extends Worker {
35
37
36
38
object PaymentWorker {
37
39
38
- def props (delay : Duration = 250 millis): Props =
40
+ def props (delay : Duration = 100 millis): Props =
39
41
Props (new PaymentWorker (delay))
40
42
41
43
}
0 commit comments