feat: treat end-of-events as end, not as an error

If there are no more events to be received from the node, treat that
as an "end of file" situation, instead of as an error. In other words,
do a normal shutdown and let a system manager restart the CI broker if
need be.

Still handle actual errors when receiving node events as errors.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2024-07-11 12:45:33 +03:00
parent ad80772033
commit 14e2eaec01
3 changed files with 21 additions and 39 deletions
+11 -14
View File
@@ -232,10 +232,9 @@ when I run bash radenv.sh bash setup-node.sh
given an installed synthetic-events
given file refsfetched.json
given file shutdown.json
given file set-rid
when I run env HOME=../homedir python3 set-rid refsfetched.json testy
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log log.txt
when I run synthetic-events synt.sock refsfetched.json --log log.txt
given an installed cib
given a directory reports
@@ -245,9 +244,9 @@ when I run chmod +x adapter.sh
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
then command is successful
when I run cibtool --db ci-broker.db event shutdown
given an installed cibtool
when I run cibtool --db ci-broker.db event shutdown
when I run cibtool --db ci-broker.db event list
when I run cibtool --db ci-broker.db run list
@@ -281,10 +280,9 @@ when I run bash radenv.sh bash setup-node.sh
given an installed synthetic-events
given file refsfetched.json
given file shutdown.json
given file set-rid
when I run env HOME=../homedir python3 set-rid refsfetched.json testy
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log log.txt
when I run synthetic-events synt.sock refsfetched.json --log log.txt
given file adapter.sh from adapter-with-url.sh
when I run chmod +x adapter.sh
@@ -383,7 +381,7 @@ given an installed synthetic-events
when I run synthetic-events synt.sock --log log.txt
given file broker.yaml
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
then stderr contains "connection to the node control socket broke"
then command is successful
~~~
@@ -409,11 +407,13 @@ when I run bash radenv.sh bash setup-node.sh
given an installed cib
given an installed synthetic-events
given file shutdown.json
given file broker.yaml
when I run synthetic-events synt.sock shutdown.json --log synt.log
when I run synthetic-events synt.sock --log synt.log
when I try to run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml insert
when I run cat synt.log
then command is successful
when I run cibtool --db ci-broker.db run list
then stdout is exactly ""
~~~
@@ -574,8 +574,7 @@ given an installed cib
given an installed synthetic-events
given file refsfetched.json
given file shutdown.json
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log synt.log
when I run synthetic-events synt.sock refsfetched.json --log synt.log
given file broker.yaml
when I try to run bash radenv.sh env RAD_SOCKET=synt.sock cib --config broker.yaml insert
@@ -604,8 +603,7 @@ given an installed cib
given an installed synthetic-events
given file refsfetched.json
given file shutdown.json
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log synt.log --repeat 1000
when I run synthetic-events synt.sock refsfetched.json --log synt.log --repeat 1000
given file broker.yaml
when I try to run bash radenv.sh env RAD_SOCKET=synt.sock cib --config broker.yaml insert
@@ -635,8 +633,7 @@ given an installed cib
given an installed synthetic-events
given file refsfetched.json
given file shutdown.json
when I run synthetic-events synt.sock refsfetched.json shutdown.json --log synt.log
when I run synthetic-events synt.sock refsfetched.json --log synt.log
given file broker.yaml from broker-allow-nothing.yaml
when I try to run bash radenv.sh env RAD_SOCKET=synt.sock cib --config broker.yaml insert
+1 -16
View File
@@ -111,10 +111,6 @@ impl NodeEventSource {
if let Some(event) = self.events.next() {
trace!("got event from local node: {event:#?}");
match event {
Ok(ref event) if Self::is_shutdown_request(event) => {
info!("got shutdown request from node control socket");
return Ok(vec![BrokerEvent::shutdown()]);
}
Ok(event) => {
trace!("got node event {:#?}", event);
let mut result = vec![];
@@ -140,21 +136,10 @@ impl NodeEventSource {
}
} else {
trace!("no more node events from control socket: iterator ended");
return Err(NodeEventError::BrokenConnection);
return Ok(vec![]);
}
}
}
fn is_shutdown_request(event: &Event) -> bool {
if let Event::RefsFetched { updated, .. } = event {
if let Some(RefUpdate::Skipped { name, .. }) = updated.first() {
if name == &RefString::try_from("shutdown").expect("create name") {
return true;
}
}
}
false
}
}
/// Possible errors from accessing the local Radicle node.
+9 -9
View File
@@ -6,7 +6,7 @@ use log::{debug, info};
use crate::{
db::{Db, DbError},
event::{BrokerEvent, EventFilter, NodeEventError, NodeEventSource},
event::{EventFilter, NodeEventError, NodeEventSource},
};
#[derive(Default)]
@@ -60,14 +60,14 @@ impl QueueAdder {
// event from the node.
'event_loop: loop {
debug!("waiting for event from node");
for e in source.event()? {
debug!("got event {e:#?}");
match e {
BrokerEvent::Shutdown => break 'event_loop,
BrokerEvent::RefChanged { .. } => {
info!("insert broker event into queue: {e:#?}");
self.db.push_queued_event(e)?;
}
let events = source.event()?;
if events.is_empty() {
break 'event_loop;
} else {
for e in events {
debug!("got event {e:#?}");
info!("insert broker event into queue: {e:#?}");
self.db.push_queued_event(e)?;
}
}
}