Skip to content

Commit d6d5a69

Browse files
committed
feat: import/export actors
1 parent 2bb7154 commit d6d5a69

40 files changed

Lines changed: 1998 additions & 30 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.tar.gz filter=lfs diff=lfs merge=lfs -text
88
*.tgz filter=lfs diff=lfs merge=lfs -text
99
engine/packages/test-snapshot-gen/snapshots/** filter=lfs diff=lfs merge=lfs -text
10+
rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/snapshots/**/kv.bin filter=lfs diff=lfs merge=lfs -text
1011

1112
**/Cargo.lock linguist-generated=true
1213

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/artifacts/openapi.json

Lines changed: 208 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/packages/api-peer/src/actors/create.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub async fn create(
2828
runner_name_selector: body.runner_name_selector,
2929
input: body.input.clone(),
3030
crash_policy: body.crash_policy,
31+
start_immediately: true,
32+
create_ts: None,
3133
// NOTE: This can forward if the user attempts to create an actor with a target dc and this dc
3234
// ends up forwarding to another.
3335
forward_request: true,

engine/packages/api-peer/src/actors/get_or_create.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub async fn get_or_create(
4848
runner_name_selector: body.runner_name_selector,
4949
input: body.input.clone(),
5050
crash_policy: body.crash_policy,
51+
start_immediately: true,
52+
create_ts: None,
5153
// NOTE: This can forward if the user attempts to create an actor with a target dc and this dc
5254
// ends up forwarding to another.
5355
forward_request: true,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use anyhow::Result;
2+
use rivet_api_builder::ApiCtx;
3+
use rivet_types::actors::CrashPolicy;
4+
use rivet_util::Id;
5+
use serde::{Deserialize, Serialize};
6+
7+
#[derive(Debug, Clone, Serialize, Deserialize)]
8+
#[serde(deny_unknown_fields)]
9+
pub struct ImportCreateQuery {
10+
pub namespace: String,
11+
}
12+
13+
#[derive(Debug, Clone, Serialize, Deserialize)]
14+
#[serde(deny_unknown_fields)]
15+
pub struct ImportCreateRequest {
16+
pub actor_id: Id,
17+
pub name: String,
18+
pub key: Option<String>,
19+
pub runner_name_selector: String,
20+
pub crash_policy: CrashPolicy,
21+
pub create_ts: i64,
22+
}
23+
24+
#[derive(Debug, Clone, Serialize, Deserialize)]
25+
#[serde(deny_unknown_fields)]
26+
pub struct ImportCreateResponse {
27+
pub actor: rivet_types::actors::Actor,
28+
}
29+
30+
#[tracing::instrument(skip_all)]
31+
pub async fn create(
32+
ctx: ApiCtx,
33+
_path: (),
34+
query: ImportCreateQuery,
35+
body: ImportCreateRequest,
36+
) -> Result<ImportCreateResponse> {
37+
let namespace = ctx
38+
.op(namespace::ops::resolve_for_name_global::Input {
39+
name: query.namespace,
40+
})
41+
.await?
42+
.ok_or_else(|| namespace::errors::Namespace::NotFound.build())?;
43+
44+
let res = ctx
45+
.op(pegboard::ops::actor::create::Input {
46+
actor_id: body.actor_id,
47+
namespace_id: namespace.namespace_id,
48+
name: body.name,
49+
key: body.key,
50+
runner_name_selector: body.runner_name_selector,
51+
crash_policy: body.crash_policy,
52+
input: None,
53+
forward_request: false,
54+
datacenter_name: None,
55+
start_immediately: false,
56+
create_ts: Some(body.create_ts),
57+
})
58+
.await?;
59+
60+
Ok(ImportCreateResponse { actor: res.actor })
61+
}

engine/packages/api-peer/src/actors/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod create;
22
pub mod delete;
33
pub mod get_or_create;
4+
pub mod import_create;
45
pub mod kv_get;
56
pub mod list;
67
pub mod list_names;

engine/packages/api-peer/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub async fn router(
2424
.route("/actors", get(actors::list::list))
2525
.route("/actors", post(actors::create::create))
2626
.route("/actors", put(actors::get_or_create::get_or_create))
27+
.route("/actors/import-create", post(actors::import_create::create))
2728
.route("/actors/{actor_id}", delete(actors::delete::delete))
2829
.route("/actors/names", get(actors::list_names::list_names))
2930
.route(

engine/packages/api-public/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ rivet-api-types.workspace = true
2222
rivet-api-util.workspace = true
2323
rivet-config.workspace = true
2424
rivet-data.workspace = true
25+
rivet-envoy-protocol.workspace = true
2526
rivet-error.workspace = true
2627
rivet-pools.workspace = true
2728
rivet-types.workspace = true
2829
rivet-util.workspace = true
2930
serde_json.workspace = true
3031
serde.workspace = true
32+
serde_bare.workspace = true
3133
subtle.workspace = true
3234
tokio.workspace = true
3335
tower-http.workspace = true

0 commit comments

Comments
 (0)