6 Commits

Author SHA1 Message Date
1a03c2471b Remove submodule 2023-12-21 16:37:21 +00:00
a476f43f28 Reset intervals correctly 2023-11-12 17:17:22 +00:00
17192b0f89 Correct merge errors 2023-11-12 10:15:29 +00:00
0419863afa Update styles for notification flash 2023-11-12 10:14:02 +00:00
827a982a40 Build dashboard 2023-11-12 10:14:02 +00:00
6e435bfc2e Add metrics
Change dashboards to load an index.html file compiled otherwise
2023-11-12 10:13:12 +00:00
2 changed files with 58 additions and 1 deletions

View File

@ -445,9 +445,30 @@ WHERE
}; };
error!("[Reminder {}] {}", self.id, message); error!("[Reminder {}] {}", self.id, message);
if *LOG_TO_DATABASE {
sqlx::query!(
"INSERT INTO stat (type, reminder_id, message) VALUES ('reminder_failed', ?, ?)",
self.id,
message,
)
.execute(pool)
.await
.expect("Could not log error to database");
}
} }
async fn log_success(&self, pool: impl Executor<'_, Database = Database> + Copy) {} async fn log_success(&self, pool: impl Executor<'_, Database = Database> + Copy) {
if *LOG_TO_DATABASE {
sqlx::query!(
"INSERT INTO stat (type, reminder_id) VALUES ('reminder_sent', ?)",
self.id,
)
.execute(pool)
.await
.expect("Could not log success to database");
}
}
async fn set_sent(&self, pool: impl Executor<'_, Database = Database> + Copy) { async fn set_sent(&self, pool: impl Executor<'_, Database = Database> + Copy) {
sqlx::query!("UPDATE reminders SET `status` = 'sent' WHERE `id` = ?", self.id) sqlx::query!("UPDATE reminders SET `status` = 'sent' WHERE `id` = ?", self.id)

View File

@ -137,6 +137,38 @@ pub async fn bot_data(cookies: &CookieJar<'_>, pool: &State<Pool<MySql>>) -> Jso
.await .await
.unwrap(); .unwrap();
let history = sqlx::query_as_unchecked!(
TimeFrame,
"SELECT
FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 86400) * 86400) AS `time_key`,
COUNT(1) AS `count`
FROM stat
WHERE
`utc_time` > DATE_SUB(NOW(), INTERVAL 31 DAY) AND
`type` = 'reminder_sent'
GROUP BY `time_key`
ORDER BY `time_key`"
)
.fetch_all(pool.inner())
.await
.unwrap();
let history_failed = sqlx::query_as_unchecked!(
TimeFrame,
"SELECT
FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(`utc_time`) / 86400) * 86400) AS `time_key`,
COUNT(1) AS `count`
FROM stat
WHERE
`utc_time` > DATE_SUB(NOW(), INTERVAL 31 DAY) AND
`type` = 'reminder_failed'
GROUP BY `time_key`
ORDER BY `time_key`"
)
.fetch_all(pool.inner())
.await
.unwrap();
let interval_count = sqlx::query!( let interval_count = sqlx::query!(
"SELECT COUNT(1) AS count "SELECT COUNT(1) AS count
FROM reminders FROM reminders
@ -174,6 +206,10 @@ pub async fn bot_data(cookies: &CookieJar<'_>, pool: &State<Pool<MySql>>) -> Jso
"once": schedule_once_long, "once": schedule_once_long,
"interval": schedule_interval_long, "interval": schedule_interval_long,
}, },
"historyLong": {
"sent": history,
"failed": history_failed,
},
"count": { "count": {
"reminders": reminder_count.count, "reminders": reminder_count.count,
"intervals": interval_count.count, "intervals": interval_count.count,