@@ -59,9 +59,9 @@ pub struct Context {
59
59
/// identity service.
60
60
pub identity : Option < lambda_runtime_client:: CognitoIdentity > ,
61
61
62
- /// The deadline for the current handler execution in nanoseconds based
62
+ /// The deadline for the current handler execution in milliseconds, based
63
63
/// on a unix `MONOTONIC` clock.
64
- pub ( super ) deadline : u128 ,
64
+ pub ( super ) deadline : i64 ,
65
65
}
66
66
67
67
impl Context {
@@ -102,9 +102,8 @@ impl Context {
102
102
103
103
/// Returns the remaining time in the execution in milliseconds. This is based on the
104
104
/// 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 ( )
108
107
}
109
108
}
110
109
@@ -114,11 +113,12 @@ pub(crate) mod tests {
114
113
use env:: { self , ConfigProvider } ;
115
114
use std:: { thread:: sleep, time} ;
116
115
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 ( )
119
119
}
120
120
121
- pub ( crate ) fn test_context ( deadline : u8 ) -> Context {
121
+ pub ( crate ) fn test_context ( timeout_secs : i64 ) -> Context {
122
122
Context {
123
123
memory_limit_in_mb : 128 ,
124
124
function_name : "test_func" . to_string ( ) ,
@@ -130,7 +130,7 @@ pub(crate) mod tests {
130
130
log_group_name : "logGroup" . to_string ( ) ,
131
131
client_context : Option :: default ( ) ,
132
132
identity : Option :: default ( ) ,
133
- deadline : get_deadline ( deadline ) ,
133
+ deadline : get_deadline ( timeout_secs ) ,
134
134
}
135
135
}
136
136
0 commit comments