-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,43 @@ | ||
use std::sync::Arc; | ||
|
||
use lapin::{Channel, ConnectionProperties}; | ||
use log::info; | ||
use server::bot::Command; | ||
use server::github_webhooks::get_webhooks_message; | ||
use server::{bot::answer, heartbeat::heartbeat_worker, job::job_completion_worker, ARGS}; | ||
use teloxide::prelude::*; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
async fn main() -> anyhow::Result<()> { | ||
dotenv::dotenv().ok(); | ||
env_logger::init(); | ||
|
||
info!("Starting AOSC BuildIt! server with args {:?}", *ARGS); | ||
|
||
let bot = Bot::from_env(); | ||
|
||
tokio::spawn(heartbeat_worker(ARGS.amqp_addr.clone())); | ||
tokio::spawn(job_completion_worker(bot.clone(), ARGS.amqp_addr.clone())); | ||
|
||
let send_request_conn = | ||
lapin::Connection::connect(&ARGS.amqp_addr, ConnectionProperties::default()) | ||
.await | ||
.unwrap(); | ||
// setup lapin connection pool | ||
let mut cfg = deadpool_lapin::Config::default(); | ||
cfg.url = Some(ARGS.amqp_addr.clone()); | ||
let pool = cfg.create_pool(Some(deadpool_lapin::Runtime::Tokio1))?; | ||
|
||
let channel = Arc::new(send_request_conn.create_channel().await.unwrap()); | ||
tokio::spawn(heartbeat_worker(pool.clone())); | ||
tokio::spawn(job_completion_worker(bot.clone(), pool.clone())); | ||
|
||
let handler = | ||
Update::filter_message().branch(dptree::entry().filter_command::<Command>().endpoint( | ||
|bot: Bot, channel: Arc<Channel>, msg: Message, cmd: Command| async move { | ||
answer(bot, msg, cmd, channel).await | ||
|bot: Bot, pool: deadpool_lapin::Pool, msg: Message, cmd: Command| async move { | ||
answer(bot, msg, cmd, pool).await | ||
}, | ||
)); | ||
|
||
let mut telegram = Dispatcher::builder(bot, handler) | ||
// Pass the shared state to the handler as a dependency. | ||
.dependencies(dptree::deps![channel.clone()]) | ||
.dependencies(dptree::deps![pool.clone()]) | ||
.enable_ctrlc_handler() | ||
.build(); | ||
|
||
tokio::select! { | ||
v = get_webhooks_message() => v, | ||
v = get_webhooks_message(pool.clone()) => v, | ||
v = telegram.dispatch() => v, | ||
}; | ||
|
||
Ok(()) | ||
} |