Skip to content

Commit

Permalink
Fix sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Dec 19, 2024
1 parent bad39a2 commit 1dc824e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions message_passing/update_with_start/lazy_initialization/workflows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from decimal import Decimal
from typing import Tuple
from typing import List, Tuple

from temporalio import workflow
from temporalio.exceptions import ApplicationError
Expand All @@ -14,14 +14,14 @@
@dataclass
class FinalizedOrder:
id: str
items: list[Tuple[ShoppingCartItem, str]]
items: List[Tuple[ShoppingCartItem, str]]
total: str


@workflow.defn
class ShoppingCartWorkflow:
def __init__(self):
self.items: list[Tuple[ShoppingCartItem, Decimal]] = []
self.items: List[Tuple[ShoppingCartItem, Decimal]] = []
self.order_submitted = False

@workflow.run
Expand All @@ -32,10 +32,7 @@ async def run(self) -> FinalizedOrder:
return FinalizedOrder(
id=workflow.info().workflow_id,
items=[(item, str(price)) for item, price in self.items],
total=str(
sum(item.quantity * price for item, price in self.items)
or Decimal("0.00")
),
total=str(sum(price for _, price in self.items) or Decimal("0.00")),
)

@workflow.update
Expand All @@ -46,9 +43,8 @@ async def add_item(self, item: ShoppingCartItem) -> str:
f"Item unavailable: {item}",
)
self.items.append((item, Decimal(price)))
return str(
sum(item.quantity * price for item, price in self.items) or Decimal("0.00")
)

return str(sum(price for _, price in self.items) or Decimal("0.00"))

@workflow.signal
def checkout(self):
Expand Down

0 comments on commit 1dc824e

Please sign in to comment.