Skip to content

Commit 875a7a4

Browse files
committed
fix(guard): clean up guard
1 parent a084bd6 commit 875a7a4

File tree

15 files changed

+166
-532
lines changed

15 files changed

+166
-532
lines changed

engine/packages/gasoline/src/ctx/standalone.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ impl StandaloneCtx {
6666
})
6767
}
6868

69+
#[tracing::instrument(skip_all)]
70+
pub fn with_ray(&self, ray_id: Id, req_id: Id) -> WorkflowResult<Self> {
71+
let mut ctx = StandaloneCtx::new(
72+
self.db.clone(),
73+
self.config.clone(),
74+
self.pools.clone(),
75+
self.cache.clone(),
76+
&self.name,
77+
ray_id,
78+
req_id,
79+
)?;
80+
81+
ctx.from_workflow = self.from_workflow;
82+
83+
Ok(ctx)
84+
}
85+
6986
#[tracing::instrument(skip_all)]
7087
pub fn new_from_activity(ctx: &ActivityCtx, req_id: Id) -> WorkflowResult<Self> {
7188
let mut ctx = StandaloneCtx::new(

engine/packages/guard-core/src/custom_serve.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use bytes::Bytes;
44
use http_body_util::Full;
55
use hyper::{Request, Response};
66
use rivet_runner_protocol as protocol;
7+
use rivet_util::Id;
78
use tokio_tungstenite::tungstenite::protocol::frame::CloseFrame;
89

910
use crate::WebSocketHandle;
1011
use crate::proxy_service::ResponseBody;
11-
use crate::request_context::RequestContext;
1212

1313
pub enum HibernationResult {
1414
Continue,
@@ -22,7 +22,8 @@ pub trait CustomServeTrait: Send + Sync {
2222
async fn handle_request(
2323
&self,
2424
req: Request<Full<Bytes>>,
25-
request_context: &mut RequestContext,
25+
ray_id: Id,
26+
req_id: Id,
2627
request_id: protocol::RequestId,
2728
) -> Result<Response<ResponseBody>>;
2829

@@ -32,9 +33,10 @@ pub trait CustomServeTrait: Send + Sync {
3233
_websocket: WebSocketHandle,
3334
_headers: &hyper::HeaderMap,
3435
_path: &str,
35-
_request_context: &mut RequestContext,
36+
_ray_id: Id,
37+
_req_id: Id,
3638
// Identifies the websocket across retries.
37-
_unique_request_id: protocol::RequestId,
39+
_request_id: protocol::RequestId,
3840
// True if this websocket is reconnecting after hibernation.
3941
_after_hibernation: bool,
4042
) -> Result<Option<CloseFrame>> {
@@ -45,7 +47,9 @@ pub trait CustomServeTrait: Send + Sync {
4547
async fn handle_websocket_hibernation(
4648
&self,
4749
_websocket: WebSocketHandle,
48-
_unique_request_id: protocol::RequestId,
50+
_ray_id: Id,
51+
_req_id: Id,
52+
_request_id: protocol::RequestId,
4953
) -> Result<HibernationResult> {
5054
bail!("service does not support websocket hibernation");
5155
}

engine/packages/guard-core/src/errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use rivet_error::*;
2-
use rivet_util::Id;
32
use serde::{Deserialize, Serialize};
43

54
#[derive(RivetError, Serialize, Deserialize)]
65
#[error(
76
"guard",
87
"rate_limit",
98
"Too many requests. Try again later.",
10-
"Too many requests to '{method} {path}' (actor_id: {actor_id:?}) from IP {ip}."
9+
"Too many requests to '{method} {path}' from IP {ip}."
1110
)]
1211
pub struct RateLimit {
13-
pub actor_id: Option<Id>,
1412
pub method: String,
1513
pub path: String,
1614
pub ip: String,

engine/packages/guard-core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod custom_serve;
44
pub mod errors;
55
pub mod metrics;
66
pub mod proxy_service;
7-
pub mod request_context;
87
mod server;
98
mod task_group;
109
pub mod types;

0 commit comments

Comments
 (0)