Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler Longhaul Tests #238

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions deploy/containerapps/apps/scheduler-actor-reminders-client.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
param appName string = 'scheduler-actor-reminders-client'
param containerPort int = 3008
param environmentName string
param location string

resource environment 'Microsoft.App/managedEnvironments@2022-03-01' existing = {
name: environmentName
}

resource schedulerActorRemindersClient 'Microsoft.App/containerApps@2022-03-01' = {
name: appName
location: location
properties: {
managedEnvironmentId: environment.id
template: {
containers: [
{
name: appName
image: 'dapriotest/${appName}:dev'
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
configuration: {
ingress: {
external: false
targetPort: containerPort
}
dapr: {
enabled: true
appId: appName
appPort: containerPort
}
}
}
}
39 changes: 39 additions & 0 deletions deploy/containerapps/apps/scheduler-actor-reminders-server.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
param appName string = 'scheduler-actor-reminders-server'
param containerPort int = 3007
param environmentName string
param location string

resource environment 'Microsoft.App/managedEnvironments@2022-03-01' existing = {
name: environmentName
}

resource schedulerActorRemindersServer 'Microsoft.App/containerApps@2022-03-01' = {
name: appName
location: location
properties: {
managedEnvironmentId: environment.id
template: {
containers: [
{
name: appName
image: 'dapriotest/${appName}:dev'
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
configuration: {
ingress: {
external: false
targetPort: containerPort
}
dapr: {
enabled: true
appId: appName
appPort: containerPort
}
}
}
}
39 changes: 39 additions & 0 deletions deploy/containerapps/apps/scheduler-jobs.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
param appName string = 'scheduler-jobs'
param containerPort int = 3006
param environmentName string
param location string

resource environment 'Microsoft.App/managedEnvironments@2022-03-01' existing = {
name: environmentName
}

resource schedulerJobs 'Microsoft.App/containerApps@2022-03-01' = {
name: appName
location: location
properties: {
managedEnvironmentId: environment.id
template: {
containers: [
{
name: appName
image: 'dapriotest/${appName}:dev'
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
configuration: {
ingress: {
external: false
targetPort: containerPort
}
dapr: {
enabled: true
appId: appName
appPort: containerPort
}
}
}
}
39 changes: 39 additions & 0 deletions deploy/containerapps/apps/scheduler-workflow.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
param appName string = 'scheduler-workflow'
param containerPort int = 3009
param environmentName string
param location string

resource environment 'Microsoft.App/managedEnvironments@2022-03-01' existing = {
name: environmentName
}

resource schedulerWorkflow 'Microsoft.App/containerApps@2022-03-01' = {
name: appName
location: location
properties: {
managedEnvironmentId: environment.id
template: {
containers: [
{
name: appName
image: 'dapriotest/${appName}:dev'
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
configuration: {
ingress: {
external: false
targetPort: containerPort
}
dapr: {
enabled: true
appId: appName
appPort: containerPort
}
}
}
}
18 changes: 17 additions & 1 deletion deploy/dapr-multi-app/dapr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ apps:
- appID: pubsub-workflow
appDirPath: ../../pubsub-workflow
appPort: 3005
command: ["dotnet","run", "--DaprHTTPAppPort=3005"]
command: ["dotnet","run", "--DaprHTTPAppPort=3005"]
- appID: scheduler-jobs
appDirPath: ../../scheduler-jobs
appPort: 3006
command: [ "go","run", "scheduler-jobs.go"]
- appID: scheduler-actor-reminders-server
appDirPath: ../../scheduler-actor-reminders/server
appPort: 3007
command: [ "go","run", "player-actor.go"]
- appID: scheduler-actor-reminders-client
appDirPath: ../../scheduler-actor-reminders/client
appPort: 3008
command: [ "go","run", "player-actor-client.go"]
- appID: scheduler-workflow
appDirPath: ../../scheduler-workflow
appPort: 3009
command: [ "go","run", "scheduler-workflow.go"]
26 changes: 25 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,28 @@ services:
image: workflow-gen
build:
context: .
dockerfile: workflow-gen/Dockerfile
dockerfile: workflow-gen/Dockerfile

scheduler-jobs:
image: scheduler-jobs
build:
context: .
dockerfile: scheduler-jobs/Dockerfile

scheduler-actor-reminders-server:
image: player-actor-server
build:
context: .
dockerfile: scheduler-actor-reminders/Dockerfile-server

scheduler-actor-reminders-client:
image: player-actor-client
build:
context: .
dockerfile: scheduler-actor-reminders/Dockerfile-client

scheduler-workflow:
image: scheduler-workflow
build:
context: .
dockerfile: scheduler-workflow/Dockerfile
25 changes: 25 additions & 0 deletions scheduler-actor-reminders/Dockerfile-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.23 as builder

# Set the working directory inside the container
WORKDIR /client

COPY go.mod go.sum ./
RUN go mod download

COPY . .

# Build the client app binary
RUN CGO_ENABLED=0 go build -o player-actor-client ./client/player-actor-client.go

# Final stage
FROM alpine:latest

WORKDIR /client

# Copy binary from the builder stage
COPY --from=builder /client/player-actor-client .

EXPOSE 3008

# Start the client
CMD ["/client/player-actor-client"]
25 changes: 25 additions & 0 deletions scheduler-actor-reminders/Dockerfile-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.23 as builder

# Set the working directory inside the container
WORKDIR /server

COPY go.mod go.sum ./
RUN go mod download

COPY . .

# Build the server app binary
RUN CGO_ENABLED=0 go build -o player-actor ./server/player-actor.go

# Final stage
FROM alpine:latest

WORKDIR /server

# Copy binary from the builder stage
COPY --from=builder /server/player-actor .

EXPOSE 3007

# Start the server
CMD ["/server/player-actor"]
51 changes: 51 additions & 0 deletions scheduler-actor-reminders/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Scheduler Actor Reminders

## Overview
This project tests the Dapr Scheduler for handling Actor Reminders using an example `PlayerActor` actor. The example
simulates a game session where a player's health increases or decays periodically, managed through Dapr Actor reminders.

## Project Structure
The `client` directory implements the client code that interacts with `PlayerActor`, specifically setting up reminders,
monitoring health, and handling shutdown. It invokes actor methods, but does not manage the actor lifecycle.

The `server` directory implements the `PlayerActor` server code, which manages a game session for a player, including
health-based reminders. This code defines the actor lifecycle and its reminder-based state changes.

## Reminders
Two reminders manage the actor's health:
- `healthReminder`:
- Increases the player's health if it is below full health.
- `healthDecayReminder`:
- Decreases the player's health periodically, simulating a natural decay over time.

When the player's health reaches 0, the client unregisters the reminders, revives the player, and restarts the reminders.

This tests the Scheduler for the underlying storage for Actor Reminders.

## How To Run the Code:
Run the server with:
```shell
dapr run --app-id player-actor --app-port 3007 --dapr-http-port 3500 --log-level debug --config ../dapr/config.yaml -- go run player-actor.go
```

Run the client with:
```shell
dapr run --app-id player-actor --app-port 3008 --dapr-http-port 3501 --dapr-grpc-port 50001 --log-level debug --config ../dapr/config.yaml -- go run player-actor-client.go
```

Note the config is using `SchedulerReminders`

Or

Build app images from `scheduler-actor-reminders` directory:
```shell
docker build -t player-actor-server -f Dockerfile-server .
docker build -t player-actor-client -f Dockerfile-client .
```

Run app containers:
```shell
# optionally add -d to both commands to run in background
docker run --name player-actor-server -p 3007:3007 player-actor-server
docker run --name player-actor-client -p 3008:3008 player-actor-client
```
Loading