Skip to content

Commit

Permalink
restyle to match dropshot, omicron, plus general style clean-up (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Aug 4, 2022
1 parent faa20da commit af778d6
Show file tree
Hide file tree
Showing 15 changed files with 1,070 additions and 1,425 deletions.
26 changes: 7 additions & 19 deletions examples/demo-provision.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*!
* Command-line tool for demo'ing saga interfaces
*/
//! Command-line tool for demo'ing saga interfaces

use anyhow::anyhow;
use anyhow::Context;
Expand Down Expand Up @@ -59,10 +57,8 @@ enum Demo {
},
}

/*
* We use a hardcoded SagaId for ease of automated testing. See the note in
* demo_prov_server_alloc().
*/
// We use a hardcoded SagaId for ease of automated testing. See the note in
// demo_prov_server_alloc().
fn make_saga_id() -> SagaId {
SagaId(Uuid::parse_str("049b2522-308d-442e-bc65-9bfaef863597").unwrap())
}
Expand Down Expand Up @@ -103,9 +99,7 @@ fn make_example_action_registry() -> Arc<ActionRegistry<ExampleSagaType>> {
Arc::new(registry)
}

/*
* "dot" subcommand
*/
// "dot" subcommand

async fn cmd_dot() -> Result<(), anyhow::Error> {
let params = ExampleParams {
Expand All @@ -117,9 +111,7 @@ async fn cmd_dot() -> Result<(), anyhow::Error> {
Ok(())
}

/*
* "info" subcommand
*/
// "info" subcommand

async fn cmd_info() -> Result<(), anyhow::Error> {
let log = make_log();
Expand Down Expand Up @@ -147,9 +139,7 @@ async fn cmd_info() -> Result<(), anyhow::Error> {
Ok(())
}

/*
* "print-log" subcommand
*/
// "print-log" subcommand

#[derive(Debug, StructOpt)]
struct PrintLogArgs {
Expand All @@ -166,9 +156,7 @@ async fn cmd_print_log(args: &PrintLogArgs) -> Result<(), anyhow::Error> {
Ok(())
}

/*
* "run" subcommand
*/
// "run" subcommand

#[derive(Debug, StructOpt)]
struct RunArgs {
Expand Down
12 changes: 6 additions & 6 deletions examples/trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ async fn saga_refund_card(
async fn saga_book_hotel(
action_context: ActionContext<TripSaga>,
) -> Result<HotelReservation, ActionError> {
/* ... */
// ...
let trip_context = action_context.user_data();
let params = action_context.saga_params::<TripParams>()?;
let hotel_name = &params.hotel_name;
Expand All @@ -301,7 +301,7 @@ async fn saga_book_hotel(
async fn saga_cancel_hotel(
action_context: ActionContext<TripSaga>,
) -> Result<(), anyhow::Error> {
/* ... */
// ...
let trip_context = action_context.user_data();
let confirmation: HotelReservation = action_context.lookup("hotel")?;
// ... (make request to another service -- must not fail)
Expand All @@ -311,7 +311,7 @@ async fn saga_cancel_hotel(
async fn saga_book_flight(
action_context: ActionContext<TripSaga>,
) -> Result<FlightReservation, ActionError> {
/* ... */
// ...
let trip_context = action_context.user_data();
let params = action_context.saga_params::<TripParams>()?;
let flight_info = &params.flight_info;
Expand All @@ -322,7 +322,7 @@ async fn saga_book_flight(
async fn saga_cancel_flight(
action_context: ActionContext<TripSaga>,
) -> Result<(), anyhow::Error> {
/* ... */
// ...
let trip_context = action_context.user_data();
let confirmation: FlightReservation = action_context.lookup("flight")?;
// ... (make request to another service -- must not fail)
Expand All @@ -332,7 +332,7 @@ async fn saga_cancel_flight(
async fn saga_book_car(
action_context: ActionContext<TripSaga>,
) -> Result<CarReservation, ActionError> {
/* ... */
// ...
let trip_context = action_context.user_data();
let params = action_context.saga_params::<TripParams>()?;
let car_info = &params.car_info;
Expand All @@ -343,7 +343,7 @@ async fn saga_book_car(
async fn saga_cancel_car(
action_context: ActionContext<TripSaga>,
) -> Result<(), anyhow::Error> {
/* ... */
// ...
let trip_context = action_context.user_data();
let confirmation: CarReservation = action_context.lookup("car")?;
// ... (make request to another service -- must not fail)
Expand Down
52 changes: 25 additions & 27 deletions src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::sync::Arc;
use thiserror::Error;
use uuid::Uuid;

/** Unique identifier for a Saga (an execution of a saga template) */
/// Unique identifier for a Saga (an execution of a saga template)
#[derive(
Clone,
Copy,
Expand All @@ -54,13 +54,11 @@ use uuid::Uuid;
pub struct SagaId(pub Uuid);
// TODO-cleanup figure out how to use custom_derive here?
NewtypeDebug! { () pub struct SagaId(Uuid); }
/*
* TODO-design In the Oxide consumer, we probably want to have the serialized
* form of ids have a prefix describing the type. This seems consumer-specific,
* though. Is there a good way to do support that? Maybe the best way to do
* this is to have the consumer have their own enum or trait that impls Display
* using the various ids provided by consumers.
*/
// TODO-design In the Oxide consumer, we probably want to have the serialized
// form of ids have a prefix describing the type. This seems consumer-specific,
// though. Is there a good way to do support that? Maybe the best way to do
// this is to have the consumer have their own enum or trait that impls Display
// using the various ids provided by consumers.
NewtypeDisplay! { () pub struct SagaId(Uuid); }
NewtypeFrom! { () pub struct SagaId(Uuid); }

Expand Down Expand Up @@ -343,9 +341,9 @@ pub struct SagaDag {
/// the actual DAG representation
///
/// Unlike [`Dag`], [`SagaDag`]'s graph can contain any type of [`Node`].
/// There is always exactly one [`InternalNode::Start`] node and exactly one
/// [`InternalNode::End`] node. The graph can contain subsagas, which are
/// always bracketed by [`InternalNode::SubsagaStart`] and
/// There is always exactly one [`InternalNode::Start`] node and exactly
/// one [`InternalNode::End`] node. The graph can contain subsagas,
/// which are always bracketed by [`InternalNode::SubsagaStart`] and
/// [`InternalNode::SubsagaEnd`] nodes.
pub(crate) graph: Graph<InternalNode, ()>,
/// the index of the [`InternalNode::Start`] node for this Saga
Expand Down Expand Up @@ -445,12 +443,12 @@ pub struct Dag {
///
/// This graph does *not* contain a [`InternalNode::Start`] or
/// [`InternalNode::End`] node. Those only make sense for `Dag`s that will
/// become top-level sagas (as opposed to subsagas). Instead, we keep track
/// of the first group of DAG (root nodes) and the last group of DAG nodes
/// (leaf nodes). Later, we'll wrap this `Dag` in either [`SagaDag`] (for
/// use as a top-level saga), in which case we'll add the start and end
/// nodes, or we'll use it as a subsaga, in which case we'll add
/// SubsagaStart and SubsagaEnd nodes.
/// become top-level sagas (as opposed to subsagas). Instead, we keep
/// track of the first group of DAG (root nodes) and the last group of
/// DAG nodes (leaf nodes). Later, we'll wrap this `Dag` in either
/// [`SagaDag`] (for use as a top-level saga), in which case we'll add
/// the start and end nodes, or we'll use it as a subsaga, in which
/// case we'll add SubsagaStart and SubsagaEnd nodes.
graph: Graph<InternalNode, ()>,

/// the initial nodes (root nodes) of the DAG
Expand Down Expand Up @@ -522,7 +520,7 @@ enum DagBuilderErrorKind {

#[error(
"subsaga node {0:?} has parameters that come from node {1:?}, but it \
does not depend on any such node"
does not depend on any such node"
)]
/// A subsaga was appended whose parameters were supposed to come from a
/// node that does not exist or that the subsaga does not depend on.
Expand Down Expand Up @@ -839,8 +837,8 @@ mod test {
));
assert_eq!(
error.to_string(),
"building saga \"test-saga\": \
saga must end with exactly one node"
"building saga \"test-saga\": saga must end with exactly \
one node"
);
}
};
Expand Down Expand Up @@ -870,8 +868,8 @@ mod test {
assert!(matches!(error.kind, DagBuilderErrorKind::EmptyStage));
assert_eq!(
error.to_string(),
"building saga \"test-saga\": \
attempted to append 0 nodes in parallel"
"building saga \"test-saga\": attempted to append 0 nodes in \
parallel"
);
}

Expand All @@ -889,8 +887,8 @@ mod test {
);
assert_eq!(
error.to_string(),
"building saga \"test-saga\": \
name was used multiple times in the same Dag: \"a\""
"building saga \"test-saga\": name was used multiple times in the \
same Dag: \"a\""
);

// error case: a DAG that duplicates names (indirect ancestor)
Expand Down Expand Up @@ -954,9 +952,9 @@ mod test {
);
assert_eq!(
error.to_string(),
"building saga \"test-saga\": \
subsaga node \"b\" has parameters that come from node \"barf\", \
but it does not depend on any such node"
"building saga \"test-saga\": subsaga node \"b\" has parameters \
that come from node \"barf\", but it does not depend on any such \
node"
);

// error case: subsaga depends on params node that doesn't exist
Expand Down
Loading

0 comments on commit af778d6

Please sign in to comment.