@@ -13,10 +13,10 @@ use actix::prelude::*;
13
13
use anyhow:: Result ;
14
14
use async_trait:: async_trait;
15
15
use colored:: Colorize ;
16
- use common:: typegraph:: Typegraph ;
17
16
use tokio:: sync:: oneshot;
18
17
19
- use common:: node:: Node ;
18
+ use crate :: com:: store:: ServerStore ;
19
+ use crate :: typegraph:: loader:: TypegraphInfos ;
20
20
21
21
use super :: console:: {
22
22
input:: { Confirm , ConfirmHandler , Select , SelectOption } ,
@@ -50,10 +50,10 @@ impl PushManagerBuilder {
50
50
self
51
51
}
52
52
53
- pub fn start ( self , node : Node , secrets : HashMap < String , String > ) -> Addr < PushManagerActor > {
53
+ pub fn start ( self ) -> Addr < PushManagerActor > {
54
54
PushManagerActor :: create ( |ctx| {
55
55
let addr = ctx. address ( ) ;
56
- let pusher = PusherActor :: new ( self . console . clone ( ) , node , secrets , addr) . start ( ) ;
56
+ let pusher = PusherActor :: new ( self . console . clone ( ) , addr) . start ( ) ;
57
57
58
58
PushManagerActor {
59
59
console : self . console ,
@@ -108,10 +108,13 @@ impl PushManagerActor {
108
108
}
109
109
}
110
110
111
- fn add_active ( & mut self , tg : & Typegraph ) -> bool {
111
+ fn add_active ( & mut self , tg_infos : & TypegraphInfos ) -> bool {
112
112
let console = self . console . clone ( ) ;
113
- let path = tg. path . clone ( ) . unwrap ( ) ;
114
- let name = tg. name ( ) . unwrap ( ) ;
113
+ let path = tg_infos. path . clone ( ) ;
114
+ let name = ServerStore :: get_response_or_fail ( & path)
115
+ . unwrap ( )
116
+ . typegraph_name
117
+ . clone ( ) ;
115
118
116
119
if !self . ensure_path ( & name, & path) {
117
120
return false ;
@@ -144,10 +147,13 @@ impl PushManagerActor {
144
147
}
145
148
}
146
149
147
- fn remove_active ( & mut self , tg : & Typegraph ) -> Option < CancelationStatus > {
150
+ fn remove_active ( & mut self , tg_infos : & TypegraphInfos ) -> Option < CancelationStatus > {
148
151
let console = self . console . clone ( ) ;
149
- let path = tg. path . clone ( ) . unwrap ( ) ;
150
- let name = tg. name ( ) . unwrap ( ) ;
152
+ let path = tg_infos. path . clone ( ) ;
153
+ let name = ServerStore :: get_response_or_fail ( & path)
154
+ . unwrap ( )
155
+ . typegraph_name
156
+ . clone ( ) ;
151
157
152
158
if !self . ensure_path ( & name, & path) {
153
159
return None ;
@@ -225,28 +231,6 @@ impl PushManagerActor {
225
231
}
226
232
}
227
233
}
228
-
229
- // pub fn apply_options(&mut self, push: Push) -> Result<Push> {
230
- // let typegraph_key = push.typegraph.get_key()?;
231
- // if let Some(options) = self.one_time_push_options.remove(&typegraph_key) {
232
- // let mut push = push;
233
- // for option in options {
234
- // match option {
235
- // OneTimePushOption::ForceReset { runtime_name } => {
236
- // let mut typegraph = (*push.typegraph).clone();
237
- // EmbeddedPrismaMigrationOptionsPatch::default()
238
- // .reset_on_drift(true)
239
- // .apply(&mut typegraph, vec![runtime_name])
240
- // .unwrap();
241
- // push.typegraph = typegraph.into();
242
- // }
243
- // }
244
- // }
245
- // Ok(push)
246
- // } else {
247
- // Ok(push)
248
- // }
249
- // }
250
234
}
251
235
252
236
impl Actor for PushManagerActor {
@@ -265,15 +249,14 @@ impl Handler<Push> for PushManagerActor {
265
249
type Result = ( ) ;
266
250
267
251
fn handle ( & mut self , push : Push , _ctx : & mut Self :: Context ) -> Self :: Result {
268
- // if self.add_active(&push.typegraph) {
269
- // // let push = self.apply_options(push).unwrap(); // TODO error handling
270
-
271
- // self.pusher.do_send(push);
272
- // } else {
273
- // let tg_name = push.typegraph.name().unwrap().cyan();
274
- // self.console
275
- // .warning(format!("Typegraph {tg_name} was not pushed."));
276
- // }
252
+ if self . add_active ( & push. typegraph ) {
253
+ self . pusher . do_send ( push) ;
254
+ } else {
255
+ let response = push. typegraph . get_response_or_fail ( ) . unwrap ( ) ;
256
+ let tg_name = response. typegraph_name . cyan ( ) ;
257
+ self . console
258
+ . warning ( format ! ( "Typegraph {tg_name} was not pushed." ) ) ;
259
+ }
277
260
}
278
261
}
279
262
@@ -346,46 +329,47 @@ impl Handler<PushFinished> for PushManagerActor {
346
329
type Result = ( ) ;
347
330
348
331
fn handle ( & mut self , msg : PushFinished , ctx : & mut Self :: Context ) -> Self :: Result {
349
-
350
332
// TODO
351
333
// NOTE: https://github.com/metatypedev/metatype/commit/169e5f402ea04372a23deaf0a44fbaa45a7cf0b7
352
334
353
335
// let name = msg.push.typegraph.name().unwrap();
336
+ let response = ServerStore :: get_response_or_fail ( & msg. push . typegraph . path ) . unwrap ( ) ;
337
+ let name = response. typegraph_name . clone ( ) ;
338
+
339
+ if msg. success {
340
+ self . console . info ( format ! (
341
+ "{} Successfully pushed typegraph {name}." ,
342
+ "✓" . green( ) ,
343
+ name = name. cyan( )
344
+ ) ) ;
345
+ }
346
+ if !self . failed_push_exists {
347
+ self . failed_push_exists = !msg. success ;
348
+ }
354
349
355
- // if msg.success {
356
- // self.console.info(format!(
357
- // "{} Successfully pushed typegraph {name}.",
358
- // "✓".green(),
359
- // name = name.cyan()
360
- // ));
361
- // }
362
- // if !self.failed_push_exists {
363
- // self.failed_push_exists = !msg.success;
364
- // }
365
-
366
- // let res = self.remove_active(&msg.push.typegraph);
367
- // let Some(CancelationStatus(is_cancelled)) = res else {
368
- // return;
369
- // };
370
-
371
- // if let Some(follow_up) = msg.follow_up {
372
- // use PushFollowUp as F;
373
- // match follow_up {
374
- // F::ScheduleRetry => {
375
- // if !is_cancelled {
376
- // self.schedule_retry(msg.push, ctx.address());
377
- // }
378
- // }
379
- // F::Interact(interaction) => {
380
- // if !is_cancelled {
381
- // let console = self.console.clone();
382
- // Arbiter::current().spawn(async move {
383
- // Self::interact(console, interaction).await;
384
- // });
385
- // }
386
- // }
387
- // }
388
- // }
350
+ let res = self . remove_active ( & msg. push . typegraph ) ;
351
+ let Some ( CancelationStatus ( is_cancelled) ) = res else {
352
+ return ;
353
+ } ;
354
+
355
+ if let Some ( follow_up) = msg. follow_up {
356
+ use PushFollowUp as F ;
357
+ match follow_up {
358
+ F :: ScheduleRetry => {
359
+ if !is_cancelled {
360
+ self . schedule_retry ( msg. push , ctx. address ( ) ) ;
361
+ }
362
+ }
363
+ F :: Interact ( interaction) => {
364
+ if !is_cancelled {
365
+ let console = self . console . clone ( ) ;
366
+ Arbiter :: current ( ) . spawn ( async move {
367
+ Self :: interact ( console, interaction) . await ;
368
+ } ) ;
369
+ }
370
+ }
371
+ }
372
+ }
389
373
}
390
374
}
391
375
0 commit comments