@@ -2,14 +2,11 @@ use crate::http;
2
2
use crate :: settings:: global_user:: GlobalUser ;
3
3
4
4
use anyhow:: Result ;
5
- use chrono:: { DateTime , Utc } ;
6
5
use cloudflare:: {
7
- endpoints:: workers:: { CreateTail , CreateTailParams , DeleteTail , SendTailHeartbeat } ,
6
+ endpoints:: workers:: { CreateTail , CreateTailParams , DeleteTail } ,
8
7
framework:: { async_api:: ApiClient , response:: ApiFailure } ,
9
8
} ;
10
9
use reqwest:: StatusCode ;
11
- use std:: time:: { SystemTime , UNIX_EPOCH } ;
12
- use tokio:: time:: { Duration , Instant } ;
13
10
use url:: Url ;
14
11
15
12
/// A tail captures `TraceEvent`s from a published Worker.
@@ -18,7 +15,6 @@ pub struct Tail {
18
15
pub user : GlobalUser ,
19
16
pub account_id : String ,
20
17
pub script_name : String ,
21
- pub expires_at : Instant ,
22
18
pub url : Option < Url > ,
23
19
pub id : Option < String > ,
24
20
}
@@ -35,7 +31,6 @@ impl Tail {
35
31
user,
36
32
account_id,
37
33
script_name,
38
- expires_at : Instant :: now ( ) ,
39
34
url,
40
35
id : None ,
41
36
}
@@ -68,7 +63,6 @@ impl Tail {
68
63
let tail = response. result ;
69
64
log:: info!( "Created tail: {:?}" , tail) ;
70
65
self . id = Some ( tail. id ) ;
71
- self . expires_at = to_instant ( tail. expires_at ) ;
72
66
self . url = Some ( Url :: parse (
73
67
& tail. url . expect ( "Expected a URL from tail response" ) ,
74
68
) ?) ;
@@ -82,35 +76,6 @@ impl Tail {
82
76
}
83
77
}
84
78
85
- /// Sends a keep-alive to the tail.
86
- pub async fn keep_alive ( & mut self ) -> Result < ( ) > {
87
- match self . id . clone ( ) {
88
- Some ( tail_id) => {
89
- match http:: cf_v4_api_client_async ( & self . user ) ?
90
- . request ( & SendTailHeartbeat {
91
- account_identifier : & self . account_id ,
92
- script_name : & self . script_name ,
93
- tail_id : & tail_id,
94
- } )
95
- . await
96
- {
97
- Ok ( response) => {
98
- log:: debug!( "Sent tail keep-alive tail: {:?}" , response. result) ;
99
- self . expires_at = to_instant ( response. result . expires_at ) ;
100
- Ok ( ( ) )
101
- }
102
- Err ( err) => {
103
- anyhow:: bail!(
104
- "Failed to keep-alive tail: {}" ,
105
- http:: format_error( err, None )
106
- )
107
- }
108
- }
109
- }
110
- _ => Ok ( ( ) ) ,
111
- }
112
- }
113
-
114
79
/// Deletes the tail and unattaches it from the Worker.
115
80
pub async fn delete ( & mut self ) -> Result < ( ) > {
116
81
match self . id . clone ( ) {
@@ -126,7 +91,6 @@ impl Tail {
126
91
log:: info!( "Deleted tail: {}" , & tail_id) ;
127
92
self . id = None ;
128
93
self . url = None ;
129
- self . expires_at = Instant :: now ( ) ;
130
94
Ok ( ( ) )
131
95
}
132
96
Err ( err) => {
@@ -137,13 +101,3 @@ impl Tail {
137
101
}
138
102
}
139
103
}
140
-
141
- /// Converts a `chrono::DateTime` into a `tokio::time::Instant`.
142
- fn to_instant ( datetime : DateTime < Utc > ) -> Instant {
143
- let delta = datetime. timestamp ( )
144
- - SystemTime :: now ( )
145
- . duration_since ( UNIX_EPOCH )
146
- . expect ( "Time is going backwards?" )
147
- . as_secs ( ) as i64 ;
148
- Instant :: now ( ) + Duration :: from_secs ( delta as u64 )
149
- }
0 commit comments