mirror of https://github.com/apibillme/broker
make scheduler send event array
This commit is contained in:
parent
bbd70d1806
commit
279a027c4b
|
@ -23,10 +23,10 @@ const useStyles = makeStyles({
|
|||
});
|
||||
|
||||
const Comments = () => {
|
||||
const state = useSSE('internal_status', {
|
||||
const state = useSSE('user', {
|
||||
initialState: {
|
||||
data: {
|
||||
value: null,
|
||||
events: null,
|
||||
},
|
||||
},
|
||||
stateReducer(state, changes) {
|
||||
|
@ -37,7 +37,9 @@ const Comments = () => {
|
|||
},
|
||||
});
|
||||
|
||||
return <p>{state.data.error !== null && <span>{state.data.error}</span>}</p>;
|
||||
console.log(state.data);
|
||||
|
||||
return <p>{state.data.events != null && <span>{state.data.events[0].data.user}</span>}</p>;
|
||||
};
|
||||
|
||||
function App() {
|
||||
|
@ -64,7 +66,7 @@ function App() {
|
|||
<CardContent>
|
||||
<Typography className={classes.title} color="textSecondary" gutterBottom component={'span'} variant={'body2'}>
|
||||
What is your name?
|
||||
<SSEProvider endpoint={sseEndpoint} options={{headers: {authorization: 'Bearer 123'}}}>
|
||||
<SSEProvider endpoint={sseEndpoint} options={{headers: {authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI3OGJjZDYxNC1jZDM5LTQzMWEtYWIyNC04OWQ5MTlkYmJmODkiLCJjb21wYW55IjoiIiwiZXhwIjoxNTgwMjU2ODA4fQ.cYFclXygM8AM_bt5I7lyGRZDhW_LL1Z1ZFgV5EHbnoI'}}}>
|
||||
<Comments />
|
||||
</SSEProvider>
|
||||
</Typography>
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -501,14 +501,18 @@ pub async fn broker() {
|
|||
let mut new_json = v.clone();
|
||||
new_json.published = true;
|
||||
let newer_json = new_json.clone();
|
||||
|
||||
let newest_json = new_json.clone();
|
||||
|
||||
let guid = Uuid::new_v4().to_string();
|
||||
let sse = SSE{id: guid, event: new_json.event, data: serde_json::to_string(&new_json.data).unwrap(), retry: Duration::from_millis(5000)};
|
||||
let mut events : Vec<Event> = Vec::new();
|
||||
events.push(newer_json);
|
||||
let events = json!({"events": events});
|
||||
let sse = SSE{id: guid, event: new_json.event, data: events.to_string(), retry: Duration::from_millis(5000)};
|
||||
let (tx, _) = CHANNEL.get(&"chan".to_owned()).unwrap();
|
||||
let _ = tx.send(sse).unwrap();
|
||||
let tree_cloned = tree.clone();
|
||||
let _ = tokio::spawn(async move {
|
||||
let _ = tree_cloned.compare_and_swap(k, Some(serde_json::to_string(&old_json_clone).unwrap().as_bytes()), Some(serde_json::to_string(&newer_json).unwrap().as_bytes()));
|
||||
let _ = tree_cloned.compare_and_swap(k, Some(serde_json::to_string(&old_json_clone).unwrap().as_bytes()), Some(serde_json::to_string(&newest_json).unwrap().as_bytes()));
|
||||
let _ = tree_cloned.flush();
|
||||
}).await;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue