Skip to content

Commit

Permalink
twiq-light: Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 20, 2022
1 parent c5173a1 commit 3cc3923
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion twiq-light/src/authorize.rs
Expand Up @@ -4,14 +4,15 @@ use anyhow::{bail, Context};
use rand::{rngs::ThreadRng, RngCore};
use sha2::{Digest, Sha256};
use time::OffsetDateTime;
use tracing::debug;
use tracing::{debug, instrument};
use url::Url;

use crate::{
store::{Token, TweetQueueStore},
twitter,
};

#[instrument(skip_all)]
pub async fn run(
store: TweetQueueStore,
client_id: String,
Expand Down
3 changes: 2 additions & 1 deletion twiq-light/src/dequeue.rs
@@ -1,6 +1,6 @@
use anyhow::bail;
use time::{format_description::well_known::Rfc3339, Duration, OffsetDateTime};
use tracing::debug;
use tracing::{debug, instrument};

use crate::{
store::{Token, TweetQueueStore},
Expand Down Expand Up @@ -42,6 +42,7 @@ async fn ensure_token(
}
}

#[instrument(skip_all)]
pub async fn run(
store: TweetQueueStore,
client_id: String,
Expand Down
3 changes: 3 additions & 0 deletions twiq-light/src/enqueue.rs
@@ -1,5 +1,8 @@
use tracing::instrument;

use crate::{domain::ScheduledTweet, store::TweetQueueStore};

#[instrument(skip_all)]
pub async fn run(store: TweetQueueStore, tweet: String) -> anyhow::Result<()> {
let mut queue = store.read_all().await?;
queue.push_back(ScheduledTweet { text: tweet });
Expand Down
2 changes: 2 additions & 0 deletions twiq-light/src/import.rs
Expand Up @@ -6,6 +6,7 @@ use time::{
format_description::{self, well_known::Iso8601},
OffsetDateTime,
};
use tracing::instrument;

#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct Item {
Expand Down Expand Up @@ -140,6 +141,7 @@ impl Item {
}
}

#[instrument(skip_all)]
pub async fn run<P: AsRef<Path>>(store: TweetStore, file: P) -> anyhow::Result<()> {
let s = fs::read_to_string(file)?;
let json: Vec<Item> = serde_json::from_str(s.trim_start_matches("window.YTD.tweet.part0 = "))?;
Expand Down
3 changes: 3 additions & 0 deletions twiq-light/src/list_queue.rs
@@ -1,5 +1,8 @@
use tracing::instrument;

use crate::store::TweetQueueStore;

#[instrument(skip_all)]
pub async fn run(store: TweetQueueStore) -> anyhow::Result<()> {
let queue = store.read_all().await?;
for scheduled_tweet in queue {
Expand Down
3 changes: 3 additions & 0 deletions twiq-light/src/reorder.rs
@@ -1,5 +1,8 @@
use tracing::instrument;

use crate::store::TweetQueueStore;

#[instrument(skip_all)]
pub async fn run(store: TweetQueueStore, src: usize, dst: usize) -> anyhow::Result<()> {
if src == dst {
return Ok(());
Expand Down
3 changes: 3 additions & 0 deletions twiq-light/src/search.rs
@@ -1,5 +1,8 @@
use tracing::instrument;

use crate::store::TweetStore;

#[instrument(skip_all)]
pub async fn run(store: TweetStore, query: Option<String>) -> anyhow::Result<()> {
let data = store.read_all()?;

Expand Down

0 comments on commit 3cc3923

Please sign in to comment.