Skip to content

Commit 3f4eeed

Browse files
Sh4rKsapessi
authored andcommitted
Convert deadline-related values to i64 and fix comments. (#27)
1 parent 771e598 commit 3f4eeed

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

lambda-runtime-client/src/client.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum LambdaHeaders {
2222
FunctionArn,
2323
/// The X-Ray trace ID generated for this invocation
2424
TraceId,
25-
/// The deadline for the function execution in nanoseconds
25+
/// The deadline for the function execution in milliseconds
2626
Deadline,
2727
/// The client context header. This field is populated when the function
2828
/// is invoked from a mobile client.
@@ -105,8 +105,8 @@ pub struct EventContext {
105105
pub aws_request_id: String,
106106
/// The X-Ray trace ID for the current invocation.
107107
pub xray_trace_id: String,
108-
/// The execution deadline for the current invocation in nanoseconds.
109-
pub deadline: u128,
108+
/// The execution deadline for the current invocation in milliseconds.
109+
pub deadline: i64,
110110
/// The client context object sent by the AWS mobile SDK. This field is
111111
/// empty unless the function is invoked using an AWS mobile SDK.
112112
pub client_context: Option<ClientContext>,
@@ -402,14 +402,13 @@ impl RuntimeClient {
402402
}
403403
};
404404

405-
let deadline: u128 = match headers.get(LambdaHeaders::Deadline.as_str()) {
406-
Some(value) => value.to_str()?.to_owned(),
405+
let deadline = match headers.get(LambdaHeaders::Deadline.as_str()) {
406+
Some(value) => value.to_str()?.parse()?,
407407
None => {
408408
error!("Response headers do not contain deadline header");
409409
return Err(ApiError::new(&format!("Missing {} header", LambdaHeaders::Deadline)));
410410
}
411-
}
412-
.parse::<u128>()?;
411+
};
413412

414413
let mut ctx = EventContext {
415414
aws_request_id,

lambda-runtime/src/context.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pub struct Context {
5959
/// identity service.
6060
pub identity: Option<lambda_runtime_client::CognitoIdentity>,
6161

62-
/// The deadline for the current handler execution in nanoseconds based
62+
/// The deadline for the current handler execution in milliseconds, based
6363
/// on a unix `MONOTONIC` clock.
64-
pub(super) deadline: u128,
64+
pub(super) deadline: i64,
6565
}
6666

6767
impl Context {
@@ -102,9 +102,8 @@ impl Context {
102102

103103
/// Returns the remaining time in the execution in milliseconds. This is based on the
104104
/// deadline header passed by Lambda's Runtime APIs.
105-
pub fn get_time_remaining_millis(&self) -> u128 {
106-
let millis = Utc::now().timestamp_millis();
107-
self.deadline - millis as u128
105+
pub fn get_time_remaining_millis(&self) -> i64 {
106+
self.deadline - Utc::now().timestamp_millis()
108107
}
109108
}
110109

@@ -114,11 +113,12 @@ pub(crate) mod tests {
114113
use env::{self, ConfigProvider};
115114
use std::{thread::sleep, time};
116115

117-
fn get_deadline(secs: u8) -> u128 {
118-
Utc::now().timestamp_millis() as u128 + (u128::from(secs) * 1_000)
116+
fn get_deadline(timeout_secs: i64) -> i64 {
117+
let deadline = Utc::now() + chrono::Duration::seconds(timeout_secs);
118+
deadline.timestamp_millis()
119119
}
120120

121-
pub(crate) fn test_context(deadline: u8) -> Context {
121+
pub(crate) fn test_context(timeout_secs: i64) -> Context {
122122
Context {
123123
memory_limit_in_mb: 128,
124124
function_name: "test_func".to_string(),
@@ -130,7 +130,7 @@ pub(crate) mod tests {
130130
log_group_name: "logGroup".to_string(),
131131
client_context: Option::default(),
132132
identity: Option::default(),
133-
deadline: get_deadline(deadline),
133+
deadline: get_deadline(timeout_secs),
134134
}
135135
}
136136

0 commit comments

Comments
 (0)