Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.

Commit 5e1d241

Browse files
author
Natalie Davidson
authored
Remove unneeded heartbeat logic with sketchy time addition (#2129)
* Remove unneeded heartbeat logic with sketchy time addition
1 parent 1e66536 commit 5e1d241

File tree

3 files changed

+3
-55
lines changed

3 files changed

+3
-55
lines changed

src/commands/tail/api.rs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ use crate::http;
22
use crate::settings::global_user::GlobalUser;
33

44
use anyhow::Result;
5-
use chrono::{DateTime, Utc};
65
use cloudflare::{
7-
endpoints::workers::{CreateTail, CreateTailParams, DeleteTail, SendTailHeartbeat},
6+
endpoints::workers::{CreateTail, CreateTailParams, DeleteTail},
87
framework::{async_api::ApiClient, response::ApiFailure},
98
};
109
use reqwest::StatusCode;
11-
use std::time::{SystemTime, UNIX_EPOCH};
12-
use tokio::time::{Duration, Instant};
1310
use url::Url;
1411

1512
/// A tail captures `TraceEvent`s from a published Worker.
@@ -18,7 +15,6 @@ pub struct Tail {
1815
pub user: GlobalUser,
1916
pub account_id: String,
2017
pub script_name: String,
21-
pub expires_at: Instant,
2218
pub url: Option<Url>,
2319
pub id: Option<String>,
2420
}
@@ -35,7 +31,6 @@ impl Tail {
3531
user,
3632
account_id,
3733
script_name,
38-
expires_at: Instant::now(),
3934
url,
4035
id: None,
4136
}
@@ -68,7 +63,6 @@ impl Tail {
6863
let tail = response.result;
6964
log::info!("Created tail: {:?}", tail);
7065
self.id = Some(tail.id);
71-
self.expires_at = to_instant(tail.expires_at);
7266
self.url = Some(Url::parse(
7367
&tail.url.expect("Expected a URL from tail response"),
7468
)?);
@@ -82,35 +76,6 @@ impl Tail {
8276
}
8377
}
8478

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-
11479
/// Deletes the tail and unattaches it from the Worker.
11580
pub async fn delete(&mut self) -> Result<()> {
11681
match self.id.clone() {
@@ -126,7 +91,6 @@ impl Tail {
12691
log::info!("Deleted tail: {}", &tail_id);
12792
self.id = None;
12893
self.url = None;
129-
self.expires_at = Instant::now();
13094
Ok(())
13195
}
13296
Err(err) => {
@@ -137,13 +101,3 @@ impl Tail {
137101
}
138102
}
139103
}
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-
}

src/commands/tail/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@ pub async fn run(
7474
)
7575
));
7676

77-
if let Err(err) = loop {
77+
loop {
7878
tokio::select! {
79-
_ = tokio::signal::ctrl_c() => break Ok(()),
80-
_ = tokio::time::sleep_until(tail.expires_at) => if let Err(err) = tail.keep_alive().await { break Err(err) }
79+
_ = tokio::signal::ctrl_c() => break
8180
}
82-
} {
83-
progress.abandon_with_message(&format!("{}", err));
8481
}
8582
}
8683

src/commands/tail/websocket.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ impl WebSocketTail {
111111
},
112112
_ = tokio::signal::ctrl_c() => {
113113
self.close(CloseCode::Away, "wrangler is closing due to ctrl-c").await
114-
},
115-
_ = tokio::time::sleep_until(self.tail.expires_at) => {
116-
self.close(CloseCode::Normal, "wrangler is closing due to expiration").await
117114
}
118115
}
119116
}

0 commit comments

Comments
 (0)