MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / start

Function start

examples/jsonrpsee_example/api/src/lib.rs:98–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96
97#[tokio::main]
98async fn start() -> std::io::Result<()> {
99 let _ = TermLogger::init(
100 LevelFilter::Trace,
101 Config::default(),
102 TerminalMode::Mixed,
103 ColorChoice::Auto,
104 );
105
106 // get env vars
107 dotenvy::dotenv().ok();
108 let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
109 let host = env::var("HOST").expect("HOST is not set in .env file");
110 let port = env::var("PORT").expect("PORT is not set in .env file");
111 let server_url = format!("{host}:{port}");
112
113 // create post table if not exists
114 let conn = Database::connect(&db_url).await.unwrap();
115 MigrationMigrator::up(&conn, None).await.unwrap();
116 SeederMigrator::up(&conn, None).await.unwrap();
117
118 let server = ServerBuilder::default()
119 .build(server_url.parse::<SocketAddr>().unwrap())
120 .await
121 .unwrap();
122
123 let rpc_impl = PpcImpl { conn };
124 let server_addr = server.local_addr().unwrap();
125 let handle = server.start(rpc_impl.into_rpc()).unwrap();
126
127 info!("starting listening {}", server_addr);
128 // let mut sig_int = signal(SignalKind::interrupt()).unwrap();
129 // let mut sig_term = signal(SignalKind::terminate()).unwrap();
130
131 tokio::select! {
132 // _ = sig_int.recv() => info!("receive SIGINT"),
133 // _ = sig_term.recv() => info!("receive SIGTERM"),
134 _ = ctrl_c() => info!("receive Ctrl C"),
135 }
136 handle.stop().unwrap();
137 info!("Shutdown program");
138 Ok(())
139}
140
141pub fn main() {
142 let result = start();

Callers 1

mainFunction · 0.70

Calls 3

initFunction · 0.85
unwrapMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected