-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
76 lines (70 loc) · 2.02 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use channels::github_release::GithubRelease;
use channels::twitter::Twitter;
use lib_channels as channels;
use lib_db as db;
use lib_digester as digester;
use lib_fetcher as fetcher;
use std::str::FromStr;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
struct Opt {
#[structopt(long)]
github_api_token: String,
#[structopt(long)]
twitter_api_key: String,
#[structopt(long)]
twitter_api_secret_key: String,
#[structopt(long)]
twitter_access_token: String,
#[structopt(long)]
twitter_access_token_secret: String,
#[structopt(long)]
database_uri: String,
#[structopt(long)]
sendgrid_api_key: String,
#[structopt(long = "app-env", default_value = "prod")]
app_env: AppEnv,
}
#[derive(StructOpt, Debug)]
enum AppEnv {
Dev,
Stg,
Prod,
}
fn main() -> Result<(), String> {
let opt = Opt::from_args();
let db_conn = db::connection_from_str(&opt.database_uri)?;
let github = GithubRelease::new(&opt.github_api_token)?;
let twitter = Twitter::new(
&opt.twitter_api_key,
&opt.twitter_api_secret_key,
&opt.twitter_access_token,
&opt.twitter_access_token_secret,
)?;
let sendgrid = digester::SendgridCredentials {
api_key: opt.sendgrid_api_key,
};
println!("Running worker in {:?} mode", opt.app_env);
fetcher::App::new(&db_conn, github, twitter).run()?;
digester::App::new(&db_conn, sendgrid, opt.app_env.into()).run()
}
impl FromStr for AppEnv {
type Err = String;
fn from_str(param: &str) -> Result<Self, String> {
match param {
"dev" => Ok(AppEnv::Dev),
"stg" => Ok(AppEnv::Stg),
"prod" => Ok(AppEnv::Prod),
unknown => Err(format!("Invalid value for app_env: {}", unknown)),
}
}
}
impl Into<digester::Env> for AppEnv {
fn into(self) -> digester::Env {
match self {
AppEnv::Dev => digester::Env::Dev,
AppEnv::Stg => digester::Env::Stg,
AppEnv::Prod => digester::Env::Prod,
}
}
}