Skip to content

Commit

Permalink
Merge pull request #31 from film42/gt/stage123
Browse files Browse the repository at this point in the history
Add a few style changes prior to release
  • Loading branch information
film42 authored Nov 12, 2023
2 parents 1d2b55f + 18dda8e commit 06fdcaa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
18 changes: 4 additions & 14 deletions examples/consumer-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ impl Worker<()> for HelloWorker {
}

#[derive(Clone)]
struct PaymentReportWorker {}
struct PaymentReportWorker;

impl PaymentReportWorker {
fn new() -> Self {
Self {}
}

async fn send_report(&self, user_guid: String) -> Result<()> {
// TODO: Some actual work goes here...
info!({"user_guid" = user_guid, "class_name" = Self::class_name()}, "Sending payment report to user");
Expand All @@ -50,13 +46,7 @@ impl Worker<PaymentReportArgs> for PaymentReportWorker {
}
}

struct FilterExpiredUsersMiddleware {}

impl FilterExpiredUsersMiddleware {
fn new() -> Self {
Self {}
}
}
struct FilterExpiredUsersMiddleware;

#[derive(Deserialize)]
struct FiltereExpiredUsersArgs {
Expand Down Expand Up @@ -190,10 +180,10 @@ async fn main() -> Result<()> {

// Add known workers
p.register(HelloWorker);
p.register(PaymentReportWorker::new());
p.register(PaymentReportWorker);

// Custom Middlewares
p.using(FilterExpiredUsersMiddleware::new()).await;
p.using(FilterExpiredUsersMiddleware).await;

// // Reset cron jobs
// periodic::destroy_all(redis.clone()).await?;
Expand Down
14 changes: 4 additions & 10 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl PaymentReportWorker {
async fn send_report(&self, user_guid: String) -> Result<()> {
// TODO: Some actual work goes here...
info!({
"user_guid" = user_guid,
"user_guid" = user_guid,
"class_name" = Self::class_name()
}, "Sending payment report to user");

Expand Down Expand Up @@ -69,13 +69,7 @@ impl Worker<PaymentReportArgs> for PaymentReportWorker {
}
}

struct FilterExpiredUsersMiddleware {}

impl FilterExpiredUsersMiddleware {
fn new() -> Self {
Self {}
}
}
struct FilterExpiredUsersMiddleware;

#[derive(Deserialize)]
struct FiltereExpiredUsersArgs {
Expand Down Expand Up @@ -106,7 +100,7 @@ impl ServerMiddleware for FilterExpiredUsersMiddleware {
error!({
"class" = &job.class,
"jid" = &job.jid,
"user_guid" = filter.user_guid
"user_guid" = filter.user_guid
}, "Detected an expired user, skipping this job");
return Ok(());
}
Expand Down Expand Up @@ -212,7 +206,7 @@ async fn main() -> Result<()> {
p.register(PaymentReportWorker::new(redis.clone()));

// Custom Middlewares
p.using(FilterExpiredUsersMiddleware::new()).await;
p.using(FilterExpiredUsersMiddleware).await;

// Reset cron jobs
periodic::destroy_all(redis.clone()).await?;
Expand Down
10 changes: 2 additions & 8 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Chain {
pub(crate) fn new_with_stats(counter: Counter) -> Self {
Self {
stack: Arc::new(RwLock::new(vec![
Box::new(RetryMiddleware::new()),
Box::new(RetryMiddleware),
Box::new(StatsMiddleware::new(counter)),
Box::new(HandlerMiddleware),
])),
Expand Down Expand Up @@ -146,13 +146,7 @@ impl ServerMiddleware for HandlerMiddleware {
}
}

struct RetryMiddleware {}

impl RetryMiddleware {
fn new() -> Self {
Self {}
}
}
struct RetryMiddleware;

#[async_trait]
impl ServerMiddleware for RetryMiddleware {
Expand Down
2 changes: 1 addition & 1 deletion tests/server_middleware_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod test {
did_process: Arc::new(Mutex::new(false)),
};
let queue = "random123".to_string();
let (mut p, mut redis) = new_base_processor(queue.clone()).await;
let (mut p, redis) = new_base_processor(queue.clone()).await;

let middleware = TestMiddleware {
should_halt: false,
Expand Down

0 comments on commit 06fdcaa

Please sign in to comment.