~joshleeb/takoto

0e862a2ecf21b3665f0892e701bf5c5dc23d1993 — Josh Leeb-du Toit 19 days ago 9ccc601 master
Add doc comments for config and error types
2 files changed, 27 insertions(+), 0 deletions(-)

M takoto-sqs/src/config.rs
M takoto-sqs/src/error.rs
M takoto-sqs/src/config.rs => takoto-sqs/src/config.rs +21 -0
@@ 1,13 1,23 @@
use serde::{Deserialize, Serialize};
use std::time::Duration;

/// Default maximum receive count for a message
pub const DEFAULT_MAX_RECV_COUNT: usize = 3;
/// Default visibility period for a message
pub const DEFAULT_VISIBILITY_PERIOD: Duration = Duration::from_secs(30);

/// Queue config
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Config {
    /// Redrive policy of the queue
    #[serde(default)]
    pub redrive: RedrivePolicy,
    /// Visibility period of a received message. Seen as the [visibility timeout] in SQS docs
    ///
    /// Default is [`DEFAULT_VISIBILITY_PERIOD`].
    ///
    /// [Visibility Timeout]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html
    /// [`DEFAULT_VISIBILITY_PERIOD`]: constant.DEFAULT_VISIBILITY_PERIOD.html
    #[serde(default = "default_visibility_period")]
    pub visibility_period: Duration,
}


@@ 18,9 28,20 @@ impl Default for Config {
    }
}

/// Queue redrive policy
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RedrivePolicy {
    /// Maximum receive count for a message before the `RedrivePolicy` is invoked
    ///
    /// Default is [`DEFAULT_MAX_RECV_COUNT`].
    ///
    /// [`DEFAULT_MAX_RECV_COUNT`]: constant.DEFAULT_MAX_RECV_COUNT.html
    pub max_recv_count: usize,
    /// DLQ url to send messages where the `RedrivePolicy` is invoked
    ///
    /// For more info, see [AWS SQS docs on dead-letter queues][dlq-docs].
    ///
    /// [dlq-docs]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html
    pub dlq_url: Option<String>,
}


M takoto-sqs/src/error.rs => takoto-sqs/src/error.rs +6 -0
@@ 7,15 7,21 @@ pub type Result<T> = StdResult<T, Error>;

#[derive(Debug, Error)]
pub enum Error {
    /// The message length was invalid.
    #[error("invalid message len: got {got}, expected in range {expected:?}")]
    InvalidMessageLength { got: usize, expected: RangeInclusive<usize> },

    /// The queue was not found.
    #[error("queue not found with url: {0:?}")]
    QueueNotFound(String),

    /// An [`io::Error`] occurred.
    ///
    /// [`io::Error`]: http://doc.rust-lang.org/std/io/struct.Error.html
    #[error(transparent)]
    Io(#[from] io::Error),

    /// Any error not part of this list.
    #[error(transparent)]
    Other(Box<dyn StdError>),
}