Skip to content

Commit

Permalink
Kotlin basics examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gvdongen committed Jan 8, 2025
1 parent c9c602f commit f20aef1
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion java/basics/src/main/java/workflows/SignupWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ public static void main(String[] args) {
curl localhost:8080/SignupWorkflow/userid1/click -H 'content-type: application/json' -d '{ "secret": "xxx"}'
- Attach back to the workflow to get the result:
curl localhost:8080/restate/workflow/SignupWorkflow/userid1/attach
curl -X POST localhost:8080/restate/workflow/SignupWorkflow/userid1/attach
*/
Empty file.
8 changes: 4 additions & 4 deletions kotlin/basics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ about how they work and how they can be run.
finished actions. The example applies creates a subscription to movie streaming services
by first creating a recurring payment and then adding the subscriptions.

* **[Building blocks](src/main/java/building_blocks/MyService.java):** Restate gives you a durable version
* **[Building blocks](src/main/kotlin/building_blocks/MyService.kt):** Restate gives you a durable version
of common building blocks like queues, promises, RPC, state, and timers.
This example shows a reference of the API and what you can do with it.

* **[Virtual Objects](src/main/java/virtual_objects/GreeterObject.java):** Stateful serverless objects
* **[Virtual Objects](src/main/kotlin/virtual_objects/GreeterObject.kt):** Stateful serverless objects
to manage durable consistent state and state-manipulating logic.

* **[Workflows](src/main/java/workflows/SignupWorkflow.java):** Workflows are durable execution tasks that can
* **[Workflows](src/main/kotlin/workflows/SignupWorkflow.kt):** Workflows are durable execution tasks that can
be submitted and awaited. They have an identity and can be signaled and queried
through durable promises. The example is a user-signup flow that takes multiple
operations, including verifying the email address.
Expand All @@ -34,8 +34,8 @@ about how they work and how they can be run.
2. Start the relevant example:
- `./gradlew -PmainClass=durable_execution.SubscriptionServiceKt run` for the Durable Execution example
- The building blocks example is not runnable and more like a reference of what you can do with the API
- `./gradlew -PmainClass=workflows.SignupWorkflowKt run` for the Workflows example
- `./gradlew -PmainClass=virtual_objects.GreeterObjectKt run` for the Virtual Objects example
- `./gradlew -PmainClass=workflows.SignupWorkflowKt run` for the Workflows example

3. Register the example at Restate server by calling
`restate -y deployment register --force localhost:9080`.
Expand Down
6 changes: 0 additions & 6 deletions kotlin/basics/src/main/kotlin/utils/data_structures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package utils

import kotlinx.serialization.Serializable

@Serializable
data class UserRole(val roleKey: String, val roleDescription: String)

@Serializable
data class Permission(val permissionKey: String, val setting: String)

@Serializable
data class SubscriptionRequest(val userId: String, val creditCard: String, val subscriptions: List<String>)

Expand Down
6 changes: 3 additions & 3 deletions kotlin/basics/src/main/kotlin/utils/stubs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ private val killProcess: Boolean = System.getenv("CRASH_PROCESS") != null

fun maybeCrash(probability: Double) {
if (Math.random() < probability) {
logger.error("A failure happened!")
logger.error("👻 A failure happened!")

if (killProcess) {
logger.error("--- CRASHING THE PROCESS ---")
logger.error("👻 --- CRASHING THE PROCESS ---")
System.exit(1)
} else {
throw RuntimeException("A failure happened!")
throw RuntimeException("👻 A failure happened!")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ curl localhost:8080/GreeterObject/mary/greet -H 'content-type: application/json'
curl localhost:8080/GreeterObject/barack/greet -H 'content-type: application/json' -d '"Hello"'
--> "Hello barack for the 1-th time."
curl localhost:8080/GreeterObject/mary/ungreet -H 'content-type: application/json' -d ''
curl -X POST localhost:8080/GreeterObject/mary/ungreet
--> "Dear mary, taking one greeting back: 0."
*/
Expand Down
2 changes: 1 addition & 1 deletion kotlin/basics/src/main/kotlin/workflows/SignupWorkflow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Check the README to learn how to run Restate.
- Then, submit the workflow via HTTP:
curl localhost:8080/SignupWorkflow/userid1/run/send -H 'content-type: application/json' -d '{ "name": "Bob", "email": "bob@builder.com" }'
- Resolve the email link via:
- Resolve the email link via / Copy it over from the service log of executing the first command:
curl localhost:8080/SignupWorkflow/userid1/click -H 'content-type: application/json' -d '{ "secret": "xxx"}'
- Attach back to the workflow to get the result:
Expand Down

0 comments on commit f20aef1

Please sign in to comment.