Skip to content

Commit 716ec96

Browse files
committed
fix: support multiple typegraph in a single file
1 parent 3c70162 commit 716ec96

File tree

6 files changed

+67
-55
lines changed

6 files changed

+67
-55
lines changed

meta-cli/src/cli/deploy.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,23 @@ mod default_mode {
260260
Arbiter::current().spawn(async move {
261261
while let Some(event) = event_rx.recv().await {
262262
match event {
263-
LoaderEvent::Typegraph(tg) => match tg.get_response_or_fail() {
263+
LoaderEvent::Typegraph(tg_infos) => match tg_infos.get_response_or_fail() {
264264
Ok(res) => {
265-
match PushResult::new(
266-
self.console.clone(),
267-
self.loader.clone(),
268-
res.as_ref().clone(),
269-
) {
270-
Ok(push) => push.finalize().await.unwrap(),
271-
Err(e) => {
272-
console.error(format!(
273-
"Failed pushing typegraph {:?}:\n{:?}",
274-
tg.path.display(),
275-
e.to_string()
276-
));
265+
for (name, res) in res.iter() {
266+
match PushResult::new(
267+
self.console.clone(),
268+
self.loader.clone(),
269+
res.clone(),
270+
) {
271+
Ok(push) => push.finalize().await.unwrap(),
272+
Err(e) => {
273+
console.error(format!(
274+
"Failed pushing typegraph {:?} at {}:\n{:?}",
275+
name,
276+
tg_infos.path.display(),
277+
e.to_string()
278+
));
279+
}
277280
}
278281
}
279282
}
@@ -394,35 +397,38 @@ mod watch_mode {
394397
let mut event_rx = event_rx;
395398
while let Some(event) = event_rx.recv().await {
396399
match event {
397-
LoaderEvent::Typegraph(tg) => {
398-
let response = ServerStore::get_response_or_fail(&tg.path)
400+
LoaderEvent::Typegraph(tg_infos) => {
401+
let responses = ServerStore::get_response_or_fail(&tg_infos.path)
399402
.unwrap()
400403
.as_ref()
401404
.to_owned();
402-
match PushResult::new(console.clone(), loader.clone(), response) {
403-
Ok(push) => {
404-
if let Err(e) = push.finalize().await {
405-
panic!("{}", e.to_string());
405+
for (name, response) in responses.into_iter() {
406+
match PushResult::new(console.clone(), loader.clone(), response) {
407+
Ok(push) => {
408+
if let Err(e) = push.finalize().await {
409+
panic!("{}", e.to_string());
410+
}
411+
RetryManager::clear_counter(&tg_infos.path);
406412
}
407-
RetryManager::clear_counter(&tg.path);
408-
}
409-
Err(e) => {
410-
let tg_path = tg.path.clone();
411-
console.error(format!(
412-
"Failed pushing typegraph {:?}:\n{:?}",
413-
tg_path.display(),
414-
e.to_string()
415-
));
416-
if let Some(delay) = RetryManager::next_delay(&tg_path) {
417-
console.info(format!(
418-
"Retry {}/{}, retrying after {}s of {:?}",
419-
delay.retry,
420-
delay.max,
421-
delay.duration.as_secs(),
413+
Err(e) => {
414+
let tg_path = tg_infos.path.clone();
415+
console.error(format!(
416+
"Failed pushing typegraph {} at {:?}:\n{:?}",
417+
name,
422418
tg_path.display(),
419+
e.to_string()
423420
));
424-
tokio::time::sleep(delay.duration).await;
425-
loader.do_send(LoadModule(Arc::new(tg_path)));
421+
if let Some(delay) = RetryManager::next_delay(&tg_path) {
422+
console.info(format!(
423+
"Retry {}/{}, retrying after {}s of {:?}",
424+
delay.retry,
425+
delay.max,
426+
delay.duration.as_secs(),
427+
tg_path.display(),
428+
));
429+
tokio::time::sleep(delay.duration).await;
430+
loader.do_send(LoadModule(Arc::new(tg_path)));
431+
}
426432
}
427433
}
428434
}

meta-cli/src/cli/serialize.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ impl Action for Serialize {
9898
while let Some(event) = event_rx.recv().await {
9999
match event {
100100
LoaderEvent::Typegraph(tg_infos) => {
101-
let tg = ServerStore::get_response_or_fail(&tg_infos.path)?.as_typegraph()?;
102-
loaded.push(tg)
101+
let tgs = ServerStore::get_response_or_fail(&tg_infos.path)?;
102+
for (_, tg) in tgs.iter() {
103+
loaded.push(tg.as_typegraph()?);
104+
}
103105
}
104106
LoaderEvent::Stopped(b) => {
105107
log::debug!("event: {b:?}");

meta-cli/src/com/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async fn command() -> impl Responder {
130130
async fn response(req_body: String) -> impl Responder {
131131
let sdk_response: SDKResponse = serde_json::from_str(&req_body).unwrap();
132132
// to be used later
133-
ServerStore::add_response(sdk_response.typegraph_path.clone(), sdk_response.clone());
133+
ServerStore::add_response(sdk_response.clone());
134134
HttpResponse::Ok()
135135
.status(StatusCode::OK)
136136
.json(CLIResponseSuccess {
@@ -153,7 +153,7 @@ pub async fn spawn_server() -> std::io::Result<()> {
153153
.service(config)
154154
.service(command)
155155
.service(response)
156-
.app_data(PayloadConfig::new(1000000 * 100)) // 100 mb
156+
.app_data(PayloadConfig::new(1000000 * 100)) // mb
157157
})
158158
.listen(tcp_listener)?
159159
.run()

meta-cli/src/com/store.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct ServerStore {
6767
secrets: HashMap<String, String>,
6868
endpoint: Endpoint,
6969
prefix: Option<String>,
70-
sdk_responses: HashMap<PathBuf, Arc<SDKResponse>>,
70+
sdk_responses: HashMap<PathBuf, Arc<HashMap<String, SDKResponse>>>,
7171
}
7272

7373
#[allow(dead_code)]
@@ -107,27 +107,32 @@ impl ServerStore {
107107
with_store(|s| s.endpoint.clone())
108108
}
109109

110-
pub fn add_response(tg_name: PathBuf, response: SDKResponse) {
110+
pub fn add_response(response: SDKResponse) {
111111
with_store_mut(|s| {
112-
s.sdk_responses.insert(tg_name, response.into());
112+
let mut name_to_res = s
113+
.sdk_responses
114+
.get(&response.typegraph_path)
115+
.map(|v| v.as_ref().to_owned())
116+
.unwrap_or_default();
117+
118+
name_to_res.insert(response.typegraph_name.clone(), response.clone());
119+
120+
s.sdk_responses
121+
.insert(response.typegraph_path.clone(), name_to_res.into());
113122
})
114123
}
115124

116-
pub fn get_response(tg_path: &PathBuf) -> Option<Arc<SDKResponse>> {
125+
pub fn get_response(tg_path: &PathBuf) -> Option<Arc<HashMap<String, SDKResponse>>> {
117126
with_store(|s| s.sdk_responses.get(tg_path).map(|v| v.to_owned()))
118127
}
119128

120-
pub fn get_response_or_fail(tg_path: &PathBuf) -> Result<Arc<SDKResponse>> {
129+
pub fn get_response_or_fail(tg_path: &PathBuf) -> Result<Arc<HashMap<String, SDKResponse>>> {
121130
match Self::get_response(tg_path) {
122131
Some(res) => Ok(res.to_owned()),
123132
None => bail!("Invalid state, no response was sent by {:?}, this could be the result of an outdated sdk", &tg_path),
124133
}
125134
}
126135

127-
pub fn get_responses() -> HashMap<PathBuf, Arc<SDKResponse>> {
128-
with_store(|s| s.sdk_responses.clone())
129-
}
130-
131136
pub fn set_migration_action_glob(option: MigrationAction) {
132137
with_store_mut(|s| s.migration_action_glob = option)
133138
}

meta-cli/src/deploy/actors/loader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ pub enum ReloadReason {
125125
DependencyChanged(PathBuf),
126126
}
127127

128+
pub struct ProcFlag {
129+
pub include: Vec<String>,
130+
}
131+
128132
#[derive(Message)]
129133
#[rtype(result = "()")]
130134
pub struct LoadModule(pub Arc<PathBuf>);

meta-cli/src/typegraph/loader/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ pub struct TypegraphInfos {
3434
}
3535

3636
impl TypegraphInfos {
37-
pub fn get_response_or_fail(&self) -> Result<Arc<SDKResponse>> {
37+
pub fn get_response_or_fail(&self) -> Result<Arc<HashMap<String, SDKResponse>>> {
3838
ServerStore::get_response_or_fail(&self.path)
3939
}
4040

41-
pub fn name(&self) -> Result<String> {
42-
let response = ServerStore::get_response_or_fail(&self.path)?;
43-
Ok(response.typegraph_name.clone())
44-
}
45-
4641
pub fn get_key(&self) -> Result<String> {
4742
let path = self
4843
.path

0 commit comments

Comments
 (0)