Created
February 2, 2024 17:48
-
-
Save natansil/710c39b8f0687c850c153191c6bff5ea to your computer and use it in GitHub Desktop.
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
package com.wix.ecom | |
import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest | |
import com.netflix.conductor.sdk.workflow.task.WorkerTask | |
import io.orkes.conductor.client.http.{OrkesWorkflowClient} | |
import io.orkes.conductor.client.{ApiClient, WorkflowClient} | |
import java.util.UUID | |
import scala.jdk.CollectionConverters.MapHasAsJava | |
object Main extends App { | |
val workers = new Workers() | |
println("Hello, World!") | |
val key = "74aa1f44-34d3-4915-8b3b-7cdb982a0a50" | |
val secret = "***REMOVED***" | |
val conductorServer = "https://play.orkes.io/api" | |
println(s"key: $key, secret: $secret, conductorServer: $conductorServer") | |
val apiClient = new ApiClient(conductorServer, key, secret) | |
val request = new StartWorkflowRequest() | |
request.setName("checkout_workflow") | |
private val checkoutId = UUID.randomUUID().toString | |
println(s"checkoutId: $checkoutId") | |
val inputData: Map[String, AnyRef] = Map("checkoutId" -> checkoutId) | |
request.setInput(inputData.asJava) | |
val workflowClient: WorkflowClient = new OrkesWorkflowClient(apiClient) | |
val workflowId = workflowClient.startWorkflow(request) | |
println("Workflow id: {}", workflowId) | |
} | |
class Workers() { | |
@WorkerTask(value = "getcartitems_ref", threadCount = 5, pollingInterval = 200) | |
def getCartItems(checkoutId: String) = | |
println(s"getCartItems: $checkoutId") | |
@WorkerTask(value = "fraud-check", threadCount = 5, pollingInterval = 200) | |
def checkForFraudTask(depositDetail: DepositDetail):FraudCheckResult = { | |
println(s"depositDetail: $depositDetail") | |
FraudCheckResult(PASS, "No fraud detected") | |
} | |
} | |
case class DepositDetail(val accountId: String, val amount: BigDecimal) | |
trait Result | |
case object PASS extends Result | |
case object FAIL extends Result | |
case class FraudCheckResult(val result: Result, val reason: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment