Skip to content

Commit

Permalink
organising things and test crates
Browse files Browse the repository at this point in the history
  • Loading branch information
wildonion committed Jun 12, 2024
1 parent 7cb1a7e commit 785a497
Show file tree
Hide file tree
Showing 12 changed files with 907 additions and 715 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions hooper/grpc/event/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ impl EventPubsubService for EventServer{
}


// grpc is the nice protocol to build message queues and brokers like rmq
// so we can create a pubsub service like:
// get a list of all grpc clients from redis cache
// then send the received message with its title (channel) to
// those ones are subscribing to the topic
Expand Down
14 changes: 13 additions & 1 deletion src/apis/http/v1/events/notif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ pub(self) async fn register_notif(
match cloned_app_state.clone().actors.as_ref().unwrap()
.consumer_actors.notif_actor.send(cloned_notif).await
{
Ok(_) => { () },
Ok(_) => {

// in here you could access the notif for an owner using
// a redis key like: notif_owner:3 which retrieve all data
// on the redis for the receiver with id 3
()

},
Err(e) => {
let source = &e.source().unwrap().to_string(); // we know every goddamn type implements Error trait, we've used it here which allows use to call the source method on the object
let err_instance = crate::error::HoopoeErrorResponse::new(
Expand Down Expand Up @@ -163,6 +170,11 @@ pub(self) async fn register_notif(

}

/* -ˋˏ✄┈┈┈┈
>_ this route is used mainly to retrieve notifications in a short polling
manner, client must call this api in an interval to fetch notifs for an
owner or whole data like every 5 seconds to simulate realtiming in client.
*/
#[get("/notif/")]
pub(self) async fn get_notif(
req: HttpRequest,
Expand Down
11 changes: 9 additions & 2 deletions src/apis/ws/v1/hoop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub(self) async fn index(

// we can convert payload stream into the ws messages using ws msg handlers
let mut buffer = vec![];
while let Some(chunk) = stream.next().await{ // reading future objects from the streamer is a mutable process
match chunk{
while let Some(get_chunk) = stream.next().await{ // reading future objects from the streamer is a mutable process
match get_chunk{
Ok(b) => {
buffer.extend_from_slice(&b);
},
Expand Down Expand Up @@ -58,6 +58,7 @@ pub(self) async fn index(

// some user inputs validation
// starting session actor probably!

// ...

/* -ˋˏ✄┈┈┈┈
Expand All @@ -66,13 +67,19 @@ pub(self) async fn index(
is established, the HTTP connection transitions to a WebSocket connection and remains
open as long as the WebSocket session is active, the ws::start function is used to start
the WebSocket connection, transitioning the HTTP connection to a WebSocket connection.
every client which is connected to the ws server is an actor which can be accessible
easily during the execution of the app to send message to that via actor message sending
pattern, this way gently makes easier for us to store clients inside the ws server by
their actor address instead of socket address.
*/
// use this: https://github.com/wildonion/gem/blob/master/core/panel/apis/clp/chat.rs
// starting a session actor for this connection
// let ws_resp = ws::start(
// ws_session_actor,
// &req,
// stream
// );


todo!()

Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ use once_cell::sync::Lazy;
use std::rc::Weak;
use tokio::sync::RwLock;
use migration::{Migrator, MigratorTrait};
use std::sync::atomic::{AtomicBool, Ordering};


// all macros in other crates will be loaded in here
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ use self::workers::producers::notif::NotifProducerActor;
#[trait_variant::make(ProductExtSend: Send)]
pub trait ProductExt{
type Product;
/*
following returns a boolean and an mpsc receiver to check the
locking status of the product and receive the result of minting
process of the product.
*/
async fn atomic_purchase_status(&self, notif_producer_actor: Addr<NotifProducerActor>) -> (bool, tokio::sync::mpsc::Receiver<Self::Product>);
/*
following returns a boolean and the product instance itself to check
the minting status of the product, if there was any error.
*/
async fn mint(&mut self, notif_producer_actor: Addr<NotifProducerActor>) -> (bool, Self::Product);
}
Loading

0 comments on commit 785a497

Please sign in to comment.