aboutsummaryrefslogtreecommitdiff
path: root/planetwars-matchrunner/src/docker_runner.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-12-03 15:57:59 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-12-03 16:09:42 +0100
commit453ff83e6cda30100e9c7d8079854f651f1e3787 (patch)
tree6cd1fe02d7354d7830fecb71874aa19c6c988b4f /planetwars-matchrunner/src/docker_runner.rs
parentc7d973406790056451af2af24630f03409a9647e (diff)
downloadplanetwars.dev-453ff83e6cda30100e9c7d8079854f651f1e3787.tar.xz
planetwars.dev-453ff83e6cda30100e9c7d8079854f651f1e3787.zip
hotfix: enable reading lines split over multiple stdout buffers
Diffstat (limited to 'planetwars-matchrunner/src/docker_runner.rs')
-rw-r--r--planetwars-matchrunner/src/docker_runner.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/planetwars-matchrunner/src/docker_runner.rs b/planetwars-matchrunner/src/docker_runner.rs
index a4415ca..04d7ecb 100644
--- a/planetwars-matchrunner/src/docker_runner.rs
+++ b/planetwars-matchrunner/src/docker_runner.rs
@@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex};
use async_trait::async_trait;
use bollard::container::{self, AttachContainerOptions, AttachContainerResults, LogOutput};
use bollard::Docker;
-use bytes::Bytes;
+use bytes::{Bytes, BytesMut};
use futures::{Stream, StreamExt};
use tokio::io::{AsyncWrite, AsyncWriteExt};
use tokio::sync::mpsc;
@@ -168,6 +168,8 @@ fn run_docker_bot(
event_bus,
match_logger,
rx,
+
+ stdout_buf: BytesMut::new(),
};
let join_handle = tokio::spawn(bot_runner.run());
@@ -198,6 +200,9 @@ pub struct DockerBotRunner {
rx: mpsc::UnboundedReceiver<RequestMessage>,
match_logger: MatchLogger,
player_id: u32,
+
+ stdout_buf: BytesMut,
+ // stderr_buf: BytesMut,
}
impl DockerBotRunner {
@@ -243,8 +248,11 @@ impl DockerBotRunner {
let log_output = item.expect("failed to get log output");
match log_output {
LogOutput::StdOut { message } => {
- // TODO: this is not correct (buffering and such)
- return Ok(message);
+ self.stdout_buf.extend_from_slice(&message);
+ if let Some(split_idx) = memchr::memchr(b'\n', &self.stdout_buf) {
+ let line = self.stdout_buf.split_to(split_idx+1);
+ return Ok(line.freeze())
+ }
}
LogOutput::StdErr { mut message } => {
// TODO