Compare commits
6 Commits
e7803b98e8
...
jude/react
Author | SHA1 | Date | |
---|---|---|---|
1a03c2471b | |||
a476f43f28 | |||
17192b0f89 | |||
0419863afa | |||
827a982a40 | |||
6e435bfc2e |
@ -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)
|
||||||
|
@ -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,
|
||||||
|
Reference in New Issue
Block a user