This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
[dev] fix windows builds and timeouts #991
Merged
EverlastingBugstopper
merged 11 commits into
avery/a-time-sync
from
avery/totally-metal
Jan 29, 2020
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
423a84d
Switch from ws-rs to tungstenite-rs
EverlastingBugstopper 6aa8b0e
wip: Add keepalive timer
EverlastingBugstopper 942b3c6
Switch from tungstenite-rs to tokio-tungstenite
EverlastingBugstopper 1433607
uses latest chrome-devtools-rs
EverlastingBugstopper 3e9681f
Use one runtime
EverlastingBugstopper 37f40bb
Merge branch 'avery/a-time-sync' into avery/totally-metal
EverlastingBugstopper 64d2c59
Merge branch 'avery/totally-metal' into avery/dev-dev
EverlastingBugstopper 030ce2e
Merge pull request #1002 from cloudflare/avery/dev-dev
EverlastingBugstopper c9e03ec
cargo fmt
EverlastingBugstopper 4a9f8f3
cargo fmt
EverlastingBugstopper d5e535d
Dont suppress errors and return ! from keep_alive
EverlastingBugstopper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use std::time::Duration; | ||
|
||
use chrome_devtools as protocol; | ||
|
||
use console::style; | ||
|
||
use futures::{future, pin_mut, StreamExt}; | ||
use futures_util::sink::SinkExt; | ||
|
||
use tokio::time; | ||
use tokio_tungstenite::connect_async; | ||
use tungstenite::protocol::Message; | ||
|
||
use url::Url; | ||
|
||
const KEEP_ALIVE_INTERVAL: u64 = 10; | ||
|
||
pub async fn listen(session_id: String) -> Result<(), failure::Error> { | ||
let socket_url = format!("wss://rawhttp.cloudflareworkers.com/inspect/{}", session_id); | ||
let socket_url = Url::parse(&socket_url)?; | ||
|
||
let (ws_stream, _) = connect_async(socket_url) | ||
.await | ||
.expect("Failed to connect to devtools instance"); | ||
|
||
let (mut write, read) = ws_stream.split(); | ||
|
||
let enable_runtime = protocol::runtime::SendMethod::Enable(1.into()); | ||
let enable_runtime = serde_json::to_string(&enable_runtime)?; | ||
let enable_runtime = Message::Text(enable_runtime.into()); | ||
write.send(enable_runtime).await?; | ||
|
||
let (keep_alive_tx, keep_alive_rx) = futures::channel::mpsc::unbounded(); | ||
tokio::spawn(keep_alive(keep_alive_tx)); | ||
let keep_alive_to_ws = keep_alive_rx.map(Ok).forward(write); | ||
|
||
let print_ws_messages = { | ||
read.for_each(|message| { | ||
async { | ||
let message = message.unwrap().into_text().unwrap(); | ||
log::info!("{}", message); | ||
let message: Result<protocol::Runtime, failure::Error> = | ||
serde_json::from_str(&message).map_err(|e| { | ||
failure::format_err!("this event could not be parsed:\n{}", e) | ||
}); | ||
if let Ok(protocol::Runtime::Event(event)) = message { | ||
match event { | ||
protocol::runtime::Event::ConsoleAPICalled(event) => { | ||
match event.r#type.as_str() { | ||
"log" => println!("{}", style(event).green()), | ||
"error" => println!("{}", style(event).red()), | ||
_ => println!("{}", style(event).yellow()), | ||
} | ||
} | ||
protocol::runtime::Event::ExceptionThrown(event) => { | ||
println!("{}", style(event).bold().red()) | ||
} | ||
_ => (), | ||
} | ||
} | ||
} | ||
}) | ||
}; | ||
pin_mut!(keep_alive_to_ws, print_ws_messages); | ||
future::select(keep_alive_to_ws, print_ws_messages).await; | ||
Ok(()) | ||
} | ||
|
||
async fn keep_alive(tx: futures::channel::mpsc::UnboundedSender<Message>) -> ! { | ||
let duration = Duration::from_millis(1000 * KEEP_ALIVE_INTERVAL); | ||
let mut interval = time::interval(duration); | ||
|
||
// this is set to 2 because we have already sent an id of 1 to enable the runtime | ||
// eventually this logic should be moved to the chrome-devtools-rs library | ||
let mut id = 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i am interested why this is 2. not because it's wrong, but it feels unusual! Might deserve a comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point - the reason it's 2 is because we have already sent |
||
|
||
loop { | ||
interval.tick().await; | ||
let keep_alive_message = protocol::runtime::SendMethod::GetIsolateId(id.into()); | ||
let keep_alive_message = serde_json::to_string(&keep_alive_message) | ||
.expect("Could not convert keep alive message to JSON"); | ||
let keep_alive_message = Message::Text(keep_alive_message.into()); | ||
tx.unbounded_send(keep_alive_message).unwrap(); | ||
id += 1; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎊