Skip to content

SpringBoot - Sync Update Example#490

Merged
tsurdilo merged 4 commits intomainfrom
springbootupdatesample
Jun 28, 2023
Merged

SpringBoot - Sync Update Example#490
tsurdilo merged 4 commits intomainfrom
springbootupdatesample

Conversation

@tsurdilo
Copy link
Copy Markdown
Contributor

@tsurdilo tsurdilo commented Jun 27, 2023

Sync Update SpringBoot Sample

This sample shows how to use update feature. Uses jpa and h2 in-memory db for the inventory.
User can enter a fishing item to purchase from inventory and define the amount.
The update validator checks if inventory has item and the amount (local activity)
The update then updates the db (local activity).

If amount you wan to purchase is > than whats in inventory the validator fails and shows message.
On success purchase the inventory table is updated dynamically..

Screen Shot 2023-06-26 at 11 43 59 PM

(this pr also includes small changes to other sample html pages, like using fragments for header and footer)

Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
@tsurdilo tsurdilo requested review from a team and antmendoza as code owners June 27, 2023 04:15
Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>

@Override
public void makePurchaseValidator(Purchase purchase) {
if (!activities.isProductInStockForPurchase(purchase)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local activities cannot be run in validators

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they have the same restriction as queries

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works as in it gets called ok. didnt see failure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not supported and It will not replay correctly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is event history that shows that local activity called in validator does get executed if that helps.
this is the path when you enter in amount thats greater than that in inventory:

Screen Shot 2023-06-27 at 1 36 10 AM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll likely not support local activities in validators but there has been talk of adding a different concept to SDKs which is backed by activities but doesn't generate history events that can be used in both query handlers and update validators.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should throw in Java (and Go) if any commands are being generated in query handlers and update validators (and side-effects FTR).

Copy link
Copy Markdown
Contributor

@Quinn-With-Two-Ns Quinn-With-Two-Ns Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. should we then open issue for it in java sdk to throw error and not allow temporal apis?

Yes, we already do

just wanted to add, having to throw TemporalFailure from update handler is weird

Do you have a suggestion on how you would implement it differently? I think the issue is your thinking of the update handler as part of the workflow like signal, but really its another sub request running inside a workflow that can succeed/fail on its own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if its possible to have a specific error idk like RejectUpdateException or something like that would be easier for users to understand (and if you throw TemporalFailure for it to still fail workflow if user really wants to do that for some reason).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that doesn't really work because if you ran an activity in a update handle and it failed by default if would fail your whole workflow instead of just your update request.

Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
Comment thread springboot/src/main/java/io/temporal/samples/springboot/SamplesController.java Outdated
Comment thread springboot/src/main/java/io/temporal/samples/springboot/update/README.md Outdated
Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
@tsurdilo
Copy link
Copy Markdown
Contributor Author

@Quinn-With-Two-Ns made all the updates let me know if its ok to get this in now (sorry im asking just have a Kafka sample coming in and wanted to get this merged fist if possible :) )

@tsurdilo tsurdilo merged commit b7c642a into main Jun 28, 2023
@tsurdilo tsurdilo deleted the springbootupdatesample branch June 28, 2023 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants