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

Rust SDK: Reserved #1030

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ run-sdk-conformance-local: ensure-agones-sdk-image
run-sdk-conformance-no-build: TIMEOUT ?= 30
run-sdk-conformance-no-build: RANDOM := $(shell bash -c 'echo $$RANDOM')
run-sdk-conformance-no-build: DELAY ?= $(shell bash -c "echo $$[ ($(RANDOM) % 5 ) + 1 ]s")
run-sdk-conformance-no-build: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch
run-sdk-conformance-no-build: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
run-sdk-conformance-no-build: ensure-agones-sdk-image
run-sdk-conformance-no-build: ensure-build-sdk-image
DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \
Expand All @@ -140,8 +140,8 @@ run-sdk-conformance-test:

# Run a conformance test for all SDKs supported
run-sdk-conformance-tests:
$(MAKE) run-sdk-conformance-test SDK_FOLDER=node TESTS=ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
$(MAKE) run-sdk-conformance-test SDK_FOLDER=go TESTS=ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
$(MAKE) run-sdk-conformance-test SDK_FOLDER=node
$(MAKE) run-sdk-conformance-test SDK_FOLDER=go
$(MAKE) run-sdk-conformance-test SDK_FOLDER=rust

# Clean package directories and binary files left
Expand Down
2 changes: 1 addition & 1 deletion examples/rust-simple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ REPOSITORY ?= gcr.io/agones-images

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
project_path := $(dir $(mkfile_path))
server_tag = $(REPOSITORY)/rust-simple-server:0.4
server_tag = $(REPOSITORY)/rust-simple-server:0.5

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
Expand Down
6 changes: 6 additions & 0 deletions examples/rust-simple/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ fn run() -> Result<(), String> {

println!("...marked Ready");

println!("Setting as Reserved for 5 seconds");
sdk.reserve(Duration::new(5, 0)).map_err(|e| format!("Could not run Reserve(): {}. Exiting!", e))?;
println!("...Reserved");

thread::sleep(Duration::new(6, 0));

println!("Getting GameServer details...");
let gameserver = sdk
.get_gameserver()
Expand Down
12 changes: 11 additions & 1 deletion sdks/rust/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::time::Duration;

use futures::{Future, Sink, Stream};
use grpcio;
use grpcio::CallOption;
use protobuf::Message;

use errors::*;
Expand Down Expand Up @@ -151,6 +150,17 @@ impl Sdk {
Ok(res)
}

/// Reserve marks the Game Server as Reserved for a given duration, at which point
/// it will return the GameServer to a Ready state.
/// Do note, the smallest unit available in the time.Duration argument is a second.
pub fn reserve(&self, duration: Duration) -> Result<()> {
let mut d = sdk::Duration::new();
d.set_seconds(duration.as_secs() as i64);

let res = self.client.reserve(&d).map(|_| ())?;
Ok(res)
}

/// Watch the backing GameServer configuration on updated
pub fn watch_gameserver<F>(&self, mut watcher: F) -> Result<()>
where
Expand Down
9 changes: 9 additions & 0 deletions site/content/en/docs/Guides/Client SDKs/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ To mark the [game session as ready]({{< relref "_index.md#ready" >}}) call `sdk.
sdk.ready()?;
```


{{% feature publishVersion-="1.0.0" %}}
To mark the game server as [reserved]({{< relref "_index.md#reserve-seconds" >}}) for a period of time, call `sdk.reserve(duration)`.

```rust
sdk.reserve(Duration::new(5, 0))?;
```
{{% /feature %}}

To mark that the [game session is completed]({{< relref "_index.md#shutdown" >}}) and the game server should be shut down call `sdk.shutdown()`.

```rust
Expand Down
10 changes: 9 additions & 1 deletion test/sdk/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ fn run() -> Result<(), String> {

println!("...marked Ready");

println!("Reserving for 5 seconds");
sdk.reserve(Duration::new(5, 0))
.map_err(|e| format!("Could not run Reserve(): {}. Exiting!", e))?;
println!("...Reserved");

println!("Allocate game server ...");
sdk.allocate()
.map_err(|e| format!("Could not run Allocate(): {}. Exiting!", e))?;
Expand All @@ -97,7 +102,10 @@ fn run() -> Result<(), String> {
.get_gameserver()
.map_err(|e| format!("Could not run GameServer(): {}. Exiting!", e))?;

println!("GameServer name: {}", gameserver.object_meta.clone().unwrap().name);
println!(
"GameServer name: {}",
gameserver.object_meta.clone().unwrap().name
);

println!("Setting a label");
let creation_ts = gameserver.object_meta.clone().unwrap().creation_timestamp;
Expand Down