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

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyBanks committed Feb 17, 2020
1 parent 6d41d9f commit 19a7bcf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -31,7 +31,7 @@ actix-rt = "1.0.0"
actix-web = "2.0.0"
argh = "0.1.3"
arrayvec = "0.5.1"
async-std = "1.5.0"
async-std = { features = ["attributes"], version = "1.5.0" }
base64 = "0.11.0"
chrono = { features = ["serde"], version = "0.4.10" }
clap = "2.32.0"
Expand Down
81 changes: 36 additions & 45 deletions src/bin/speedruns.rs
@@ -1,24 +1,40 @@
#![allow(missing_docs, clippy::useless_attribute, clippy::useless_vec)]
#![warn(
missing_debug_implementations,
clippy::option_unwrap_used,
clippy::result_unwrap_used
)]
#![allow(missing_docs, clippy::useless_attribute, clippy::useless_vec, unused)]
#![warn(missing_debug_implementations)]

#[allow(unused)] use log::{debug, error, info, trace, warn};
use async_std::prelude::*;

use std::{collections::BTreeMap, rc::Rc, sync::Arc};
use std::{collections::BTreeMap, rc::Rc, sync::Arc, time::Duration};

#[async_std::main]
async fn main() {
#[allow(unused_mut)]
let mut app = MyApp::new();

loop {
sleep(Duration::from_secs(5)).await;

let request = "hello";

async_std::task::spawn(app.handle_request(request));
}
}

struct MyApp {
database: Arc<Database>,
}

impl MyApp {
fn new() -> Self {
MyApp {
database: Arc::new(Database::new()),
}
}

// requirement: we need this to be able to keep running even if we update the
// database, ideally in a consistent way.
// so sleep for 5 seconds
async fn handle_request(self) -> String {
"hello world".to_string()
async fn handle_request(&self, request: &str) -> String {
sleep(Duration::from_secs(5)).await;
request.to_string()
}
}

Expand All @@ -27,41 +43,16 @@ struct Database {
index_user_by_name: BTreeMap<String, u64>,
}

struct User {
id: u64,
name: String,
}

#[actix_rt::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Args = argh::from_env();

if args.quiet {
std::env::set_var("RUST_LOG", "error");
} else if args.verbose {
std::env::set_var("RUST_LOG", "debug,speedruns=trace");
} else if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
impl Database {
fn new() -> Self {
Database {
table_user: Default::default(),
index_user_by_name: Default::default(),
}
}

pretty_env_logger::init();

let mut app = MyApp::new();

//

Ok(())
}

#[derive(argh::FromArgs, PartialEq, Debug)]
/// Tools for importing and serving some data from the speedrun.com API.
pub struct Args {
/// silence log output except for errors. overrides --verbose and RUST_LOG.
#[argh(switch, short = 'q')]
quiet: bool,

/// enables maximum logging for our code and debug logging for dependencies. overrides
/// RUST_LOG.
#[argh(switch, short = 'v')]
verbose: bool,
struct User {
id: u64,
name: String,
}

0 comments on commit 19a7bcf

Please sign in to comment.