Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Fix connected status toggle & agents count (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
feymartynov committed Aug 19, 2020
1 parent e6a577a commit e971df1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/app/endpoint/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use async_std::stream;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use serde_derive::{Deserialize, Serialize};
use svc_agent::mqtt::{
IncomingRequestProperties, IntoPublishableMessage, OutgoingResponse, ResponseStatus,
use svc_agent::{
mqtt::{IncomingRequestProperties, IntoPublishableMessage, OutgoingResponse, ResponseStatus},
Addressable,
};
use svc_error::Error as SvcError;
use uuid::Uuid;
Expand Down Expand Up @@ -359,7 +360,7 @@ impl RequestHandler for ConnectHandler {
Ok(req) => {
let conn = context.db().get()?;

db::agent::UpdateQuery::new(context.agent_id(), room.id())
db::agent::UpdateQuery::new(reqp.as_agent_id(), room.id())
.status(db::agent::Status::Connected)
.execute(&conn)?;

Expand Down
5 changes: 4 additions & 1 deletion src/db/janus_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ const LEAST_LOADED_SQL: &str = r#"
ON rtc.room_id = rl.room_id
LEFT JOIN janus_rtc_stream AS jrs
ON jrs.rtc_id = rtc.id
WHERE UPPER(jrs.time) IS NULL
GROUP BY jrs.backend_id
)
SELECT jb.*
Expand All @@ -219,6 +220,7 @@ const LEAST_LOADED_SQL: &str = r#"
LEFT JOIN room AS r2
ON 1 = 1
WHERE r2.id = $1
AND UPPER(jrs.time) IS NULL
AND COALESCE(jb.capacity, 2147483647) - COALESCE(jbl.taken, 0) > COALESCE(r2.reserve, 0)
ORDER BY COALESCE(jb.capacity, 2147483647) - COALESCE(jbl.taken, 0) DESC
LIMIT 1
Expand All @@ -237,13 +239,14 @@ pub(crate) fn least_loaded(room_id: Uuid, conn: &PgConnection) -> Result<Option<
////////////////////////////////////////////////////////////////////////////////

pub(crate) fn agents_count(backend_id: &AgentId, conn: &PgConnection) -> Result<i64, Error> {
use diesel::dsl::count;
use diesel::dsl::{count, sql};
use diesel::prelude::*;

agent::table
.inner_join(rtc::table.on(rtc::room_id.eq(agent::room_id)))
.inner_join(janus_rtc_stream::table.on(janus_rtc_stream::rtc_id.eq(rtc::id)))
.filter(janus_rtc_stream::backend_id.eq(backend_id))
.filter(sql("UPPER(\"janus_rtc_stream\".\"time\") IS NULL"))
.filter(agent::status.eq(AgentStatus::Connected))
.select(count(agent::id))
.get_result(conn)
Expand Down

0 comments on commit e971df1

Please sign in to comment.