An open API service indexing awesome lists of open source software.

https://github.com/peterhellberg/pizza-delivery-simulator

Small example project of using Temporal via their Go SDK
https://github.com/peterhellberg/pizza-delivery-simulator

example go temporal

Last synced: 22 days ago
JSON representation

Small example project of using Temporal via their Go SDK

Awesome Lists containing this project

README

          

# Pizza Delivery Simulator 🍕

> [!Tip]
> This is a notebook that can be used with the [Runme CLI](https://docs.runme.dev/installation/cli) 📚
>
> _Installation of the Runme CLI:_
> - **On macOS:** `brew install runme`
> - **Using Go:** `go install github.com/stateful/runme@latest`
> - **Binaries:**

## Plan _(not all implemented yet)_

- Workflow: Customer places an order.
- Activities:
- [x] Place order (for a known customer)
- [x] Assign delivery driver (via frontend `pizza-delivery-dashboard`)
- [ ] Driver reports progress via Temporal signals _(e.g., “Stuck in traffic”, “Almost there”)_.

## Dependencies

- https://go.dev/
- https://github.com/golang/go
- https://temporal.io/
- https://temporal.io/setup/install-temporal-cli
- https://github.com/temporalio/temporal
- https://github.com/temporalio/sdk-go
- https://jqlang.org/

## Frontends

### [pizza-delivery-dashboard](/frontends/pizza-delivery-dashboard)

2 orders waiting to be assigned.

## Commands

### Execute

#### GetMenu

```sh { name=get-menu excludeFromRunAll=true }
temporal workflow execute -t pizza --name GetMenu
```

#### PlaceOrder

```sh { name=place-order }
export PIZZA="5"
export NAME="Peter"

temporal workflow execute -t pizza --name PlaceOrder \
-i "$(jq -c -n '{name:env.NAME,pizza:env.PIZZA|tonumber}')"
```

### Server

```sh { name=temporal-dev-server }
temporal server start-dev --ip=0.0.0.0 -f=pds.db
```

#### Search attributes

```sh { name=temporal-create-search-attributes }
temporal operator search-attribute create --name DriverAssigned --type Bool
temporal operator search-attribute create --name DriverID --type Keyword
temporal operator search-attribute create --name OrderID --type Keyword
```

### Worker

```sh { name=worker }
go run ./worker | jq
```

### Dashboard

```sh { name=dashboard }
go run ./frontends/pizza-delivery-dashboard
```

### Install `temporal` and `jq` using [Homebrew](https://brew.sh/) 🍏

```sh { name=brew-install excludeFromRunAll=true }
# Install temporal and jq using brew
if ! [ -x "$(command -v brew)" ]; then
echo 'Error: brew is not installed.' >&2
exit 1
fi

brew install temporal jq
```