aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2021-01-16 21:38:22 -0500
committerChristine Dodrill <me@christine.website>2021-01-16 21:38:22 -0500
commit4bcc848bb178d9e4372ba13b750d620cabc2a9ac (patch)
treee2a97a5a03c934de6307b3d543d5f4b249675ce7 /src
parent17af42bc698237d1560b8add144641ae3950b469 (diff)
downloadxesite-4bcc848bb178d9e4372ba13b750d620cabc2a9ac.tar.xz
xesite-4bcc848bb178d9e4372ba13b750d620cabc2a9ac.zip
move poking services into app boot after systemd notify
Signed-off-by: Christine Dodrill <me@christine.website>
Diffstat (limited to 'src')
-rw-r--r--src/app/mod.rs1
-rw-r--r--src/app/poke.rs86
-rw-r--r--src/main.rs37
3 files changed, 109 insertions, 15 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs
index e763792..6c01b2f 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -5,6 +5,7 @@ use std::{fs, path::PathBuf};
use tracing::{error, instrument};
pub mod markdown;
+pub mod poke;
#[derive(Clone, Deserialize)]
pub struct Config {
diff --git a/src/app/poke.rs b/src/app/poke.rs
new file mode 100644
index 0000000..dd6f9fe
--- /dev/null
+++ b/src/app/poke.rs
@@ -0,0 +1,86 @@
+use color_eyre::eyre::Result;
+use std::{env, time::Duration};
+use tokio::time::delay_for;
+
+#[instrument(err)]
+pub async fn the_cloud() -> Result<()> {
+ info!("waiting for things to settle");
+ delay_for(Duration::from_secs(10)).await;
+
+ info!("purging cloudflare cache");
+ cloudflare().await?;
+
+ info!("waiting for the cloudflare cache to purge globally");
+ delay_for(Duration::from_secs(45)).await;
+
+ info!("poking mi");
+ mi().await?;
+
+ info!("poking bing");
+ bing().await?;
+
+ info!("poking google");
+ google().await?;
+
+ Ok(())
+}
+
+#[instrument(err)]
+async fn bing() -> Result<()> {
+ let cli = reqwest::Client::new();
+ cli.get("https://www.bing.com/ping")
+ .query(&[("sitemap", "https://christine.website/sitemap.xml")])
+ .header("User-Agent", crate::APPLICATION_NAME)
+ .send()
+ .await?
+ .error_for_status()?;
+
+ Ok(())
+}
+
+#[instrument(err)]
+async fn google() -> Result<()> {
+ let cli = reqwest::Client::new();
+ cli.get("https://www.google.com/ping")
+ .query(&[("sitemap", "https://christine.website/sitemap.xml")])
+ .header("User-Agent", crate::APPLICATION_NAME)
+ .send()
+ .await?
+ .error_for_status()?;
+
+ Ok(())
+}
+
+#[instrument(err)]
+async fn cloudflare() -> Result<()> {
+ let cli = cfcache::Client::new(env::var("CF_TOKEN")?, env::var("CF_ZONE_ID")?)?;
+ cli.purge(
+ vec![
+ "https://christine.website/sitemap.xml",
+ "https://christine.website",
+ "https://christine.website/blog",
+ "https://christine.website/blog.atom",
+ "https://christine.website/blog.json",
+ "https://christine.website/blog.rss",
+ "https://christine.website/gallery",
+ "https://christine.website/talks",
+ "https://christine.website/resume",
+ "https://christine.website/signalboost",
+ "https://christine.website/feeds",
+ ]
+ .into_iter()
+ .map(|i| i.to_string())
+ .collect(),
+ )
+ .await?;
+
+ Ok(())
+}
+
+#[instrument(err)]
+async fn mi() -> Result<()> {
+ let cli = mi::Client::new(env::var("MI_TOKEN")?, crate::APPLICATION_NAME.to_string())?;
+ cli.refresh().await?;
+
+ Ok(())
+}
diff --git a/src/main.rs b/src/main.rs
index 285bb93..91cd12b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -39,21 +39,6 @@ async fn main() -> Result<()> {
.await?,
);
- match sdnotify::SdNotify::from_env() {
- Ok(ref mut n) => {
- n.notify_ready().map_err(|why| {
- error!("can't signal readiness to systemd: {}", why);
- why
- })?;
- n.set_status(format!("hosting {} posts", state.clone().everything.len()))
- .map_err(|why| {
- error!("can't signal status to systemd: {}", why);
- why
- })?;
- }
- Err(why) => error!("not running under systemd with Type=notify: {}", why),
- }
-
let healthcheck = warp::get().and(warp::path(".within").and(warp::path("health")).map(|| "OK"));
let base = warp::path!("blog" / ..);
@@ -222,6 +207,28 @@ async fn main() -> Result<()> {
.with(warp::log(APPLICATION_NAME))
.recover(handlers::rejection);
+ match sdnotify::SdNotify::from_env() {
+ Ok(ref mut n) => {
+ // shitty heuristic for detecting if we're running in prod
+ tokio::spawn(async {
+ if let Err(why) = app::poke::the_cloud().await {
+ error!("Unable to poke the cloud: {}", why);
+ }
+ });
+
+ n.notify_ready().map_err(|why| {
+ error!("can't signal readiness to systemd: {}", why);
+ why
+ })?;
+ n.set_status(format!("hosting {} posts", state.clone().everything.len()))
+ .map_err(|why| {
+ error!("can't signal status to systemd: {}", why);
+ why
+ })?;
+ }
+ Err(why) => error!("not running under systemd with Type=notify: {}", why),
+ }
+
warp::serve(site)
.run((
[0, 0, 0, 0],