Skip to content

Commit

Permalink
Rebrand (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyja authored Mar 5, 2024
1 parent 0273651 commit 48eac6a
Show file tree
Hide file tree
Showing 39 changed files with 2,870 additions and 163 deletions.

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

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

30 changes: 23 additions & 7 deletions cja/src/cron/registry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, future::Future, pin::Pin, time::Duration};

use chrono::{OutOfRangeError, Utc};
use miette::Diagnostic;
use tokio::time::Instant;
use tracing::error;

use crate::{app_state::AppState as AS, jobs::Job};
Expand Down Expand Up @@ -59,6 +59,7 @@ pub(super) struct CronJob<AppState: AS> {
pub enum TickError {
JobError(String),
SqlxError(sqlx::Error),
NegativeDuration(OutOfRangeError),
}

impl<AppState: AS> CronJob<AppState> {
Expand All @@ -73,33 +74,48 @@ impl<AppState: AS> CronJob<AppState> {
pub(crate) async fn tick(
&self,
app_state: AppState,
last_enqueue_map: &mut HashMap<&str, Instant>,
last_enqueue_map: &HashMap<&str, chrono::DateTime<Utc>>,
) -> Result<(), TickError> {
let last_enqueue = last_enqueue_map.get(self.name);
let context = format!("Cron@{}", app_state.version());
let now = Utc::now();

if let Some(last_enqueue) = last_enqueue {
let elapsed = last_enqueue.elapsed();
let elapsed = now - last_enqueue;
let elapsed = elapsed.to_std().map_err(TickError::NegativeDuration)?;
if elapsed > self.interval {
tracing::info!(
task_name = self.name,
time_since_last_run =? elapsed,
"Enqueuing Task"
);
(self.func)
.run(app_state, context)
.run(app_state.clone(), context)
.await
.map_err(TickError::JobError)?;
last_enqueue_map.insert(self.name, Instant::now());
}
} else {
tracing::info!(task_name = self.name, "Enqueuing Task for first time");
(self.func)
.run(app_state, context)
.run(app_state.clone(), context)
.await
.map_err(TickError::JobError)?;
last_enqueue_map.insert(self.name, Instant::now());
}
sqlx::query!(
"INSERT INTO Crons (cron_id, name, last_run_at, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (name)
DO UPDATE SET
last_run_at = $3",
uuid::Uuid::new_v4(),
self.name,
now,
now,
now
)
.execute(app_state.db())
.await
.map_err(TickError::SqlxError)?;

Ok(())
}
Expand Down
18 changes: 14 additions & 4 deletions cja/src/cron/worker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, time::Duration};

use tokio::time::Instant;
use chrono::{DateTime, Utc};

use crate::app_state::AppState as AS;

Expand All @@ -18,11 +18,21 @@ impl<AppState: AS> Worker<AppState> {

pub async fn run(self) -> Result<(), TickError> {
let worker_id = uuid::Uuid::new_v4();
let mut last_enqueue_map: HashMap<&str, Instant> = HashMap::new();

tracing::debug!("Starting cron loop");
loop {
self.tick(&worker_id, &mut last_enqueue_map).await?;
let last_runs = sqlx::query!(
"SELECT name, max(last_run_at) as last_run_at FROM Crons GROUP BY name"
)
.fetch_all(self.state.db())
.await
.map_err(TickError::SqlxError)?;

let last_run_map: HashMap<&str, DateTime<Utc>> = last_runs
.iter()
.map(|row| (row.name.as_str(), row.last_run_at.unwrap_or_default()))
.collect();
self.tick(&worker_id, &last_run_map).await?;

tokio::time::sleep(Duration::from_secs(60)).await;
}
Expand All @@ -32,7 +42,7 @@ impl<AppState: AS> Worker<AppState> {
async fn tick(
&self,
worker_id: &uuid::Uuid,
last_enqueue_map: &mut HashMap<&str, Instant>,
last_enqueue_map: &HashMap<&str, chrono::DateTime<Utc>>,
) -> Result<(), TickError> {
for job in self.registry.jobs.values() {
job.tick(self.state.clone(), last_enqueue_map).await?;
Expand Down
2 changes: 2 additions & 0 deletions db/migrations/20240228040146_AddCrons.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add migration script here
DROP TABLE Crons;
17 changes: 17 additions & 0 deletions db/migrations/20240228040146_AddCrons.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add migration script here
CREATE TABLE
Crons (
cron_id UUID PRIMARY KEY,
name TEXT NOT NULL,
last_run_at TIMESTAMP
WITH
TIME ZONE NOT NULL,
created_at TIMESTAMP
WITH
TIME ZONE NOT NULL,
updated_at TIMESTAMP
WITH
TIME ZONE NOT NULL
);

CREATE UNIQUE INDEX idx_crons_name ON Crons (name);
2 changes: 1 addition & 1 deletion server/src/http_server/pages/blog/md/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl IntoHtml for Code {
}

Ok(html! {
pre class="my-4 py-4 bg-coding_background px-8 overflow-x-auto max-w-vw" { code { (PreEscaped(html_generator.finalize())) } }
pre class="my-4 py-4 bg-coding_background px-8 overflow-x-auto max-w-vw text-codeText" { code { (PreEscaped(html_generator.finalize())) } }
})
}
}
Expand Down
8 changes: 6 additions & 2 deletions server/src/http_server/pages/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ pub(crate) async fn home_page(
Ok(base(
html! {
(constrained_width(html! {
."md:bg-header-background bg-cover bg-left bg-no-repeat mb-24" {
."flex bg-right-bottom bg-no-repeat mb-24 justify-between" {
."md:w-[60%]" {
h1 class="text-2xl sm:text-4xl font-medium leading-tight pt-8 md:pt-16 pb-4" {
"Educational & entertaining content for developers of all skill levels"
"Learn, Code, Develop"
}

h3 class="text-lg sm:text-2xl text-subtitle leading-tight mb-8" {
Expand All @@ -58,6 +58,10 @@ pub(crate) async fn home_page(
(LinkButton::primary(html!("View Posts"), "/posts"))
}
}

div class="hidden md:w-[35%] md:flex" {
img src="/static/headshot-bg-removed.webp" alt="Corey's Headshot" class="mt-auto" {}
}
}

div class="flex flex-col md:flex-row md:space-x-8" {
Expand Down
2 changes: 1 addition & 1 deletion server/src/http_server/pages/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl StatusTag {
impl Render for StatusTag {
fn render(&self) -> Markup {
html! {
span class="inline-flex items-center gap-x-1.5 rounded-md px-2 py-1 text-xs font-medium text-white ring-1 ring-inset ring-grey-800" {
span class="inline-flex items-center gap-x-1.5 rounded-md px-2 py-1 text-xs font-medium text-text ring-1 ring-inset ring-grey-800" {
svg class=(format!("h-1.5 w-1.5 {}", self.color_class())) viewBox="0 0 6 6" aria-hidden="true" {
circle cx="3" cy="3" r="3";
}
Expand Down
1 change: 0 additions & 1 deletion server/src/http_server/pages/videos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ pub(crate) async fn video_get(
Ok(base_constrained(
html! {
@if let Some(video) = video {
(video.title)
h1 class="text-2xl" { (video.title) }
@if let Some(published_at) = video.published_at {
subtitle class="block text-lg text-subtitle mb-8 " { (published_at.format("%Y-%m-%d")) }
Expand Down
3 changes: 1 addition & 2 deletions server/src/http_server/templates/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum ButtonType {
impl ButtonType {
fn classes(&self) -> &str {
match &self {
ButtonType::Primary => "bg-secondary-400",
ButtonType::Primary => "bg-berryBlue text-almostBackground",
ButtonType::Secondary => "bg-background border",
}
}
Expand All @@ -48,7 +48,6 @@ impl ButtonType {
impl Render for LinkButton {
fn render(&self) -> Markup {
let mut classes = vec![
"text-text",
"px-8",
"py-4",
"rounded",
Expand Down
8 changes: 4 additions & 4 deletions server/src/http_server/templates/footer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use maud::{html, Markup, PreEscaped};

use crate::http_server::templates::{LOGO_MONOCHROME_SVG, MAX_WIDTH_CONTAINER_CLASSES};
use crate::http_server::templates::{LOGO_FLAT_SVG, MAX_WIDTH_CONTAINER_CLASSES};

pub fn newsletter_signup_footer() -> Markup {
html! {
Expand Down Expand Up @@ -28,7 +28,7 @@ pub fn newsletter_signup_footer() -> Markup {
input
type="submit"
value="Subscribe"
class="bg-secondary-400 rounded-lg px-8 py-2"
class="bg-berryBlue rounded-lg px-8 py-2"
;
}
}
Expand All @@ -39,11 +39,11 @@ pub fn footer() -> Markup {
html! {
div class="flex-grow mb-24" {}
(newsletter_signup_footer())
div ."min-h-[100px] bg-subtitle" {
div ."min-h-[100px] bg-footer" {
div ."flex ".(MAX_WIDTH_CONTAINER_CLASSES) {
div class="max-w-[10rem] sm:max-w-[15rem] min-w-[100px] py-8 flex-grow" {
a href="/" {
(PreEscaped(LOGO_MONOCHROME_SVG))
(PreEscaped(LOGO_FLAT_SVG))
}
}

Expand Down
19 changes: 15 additions & 4 deletions server/src/http_server/templates/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Borrow;

use maud::{html, Markup, PreEscaped, Render};

use crate::http_server::templates::LOGO_SVG;
use crate::http_server::templates::LOGO_DARK_FLAT_SVG;

pub struct OpenGraph {
pub title: String,
Expand Down Expand Up @@ -62,12 +62,23 @@ pub fn head(og: impl Borrow<OpenGraph>) -> Markup {

link rel="preconnect" href="https://fonts.googleapis.com" {}
link rel="preconnect" href="https://fonts.gstatic.com" crossorigin {}
link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500;600;700&&display=swap" rel="stylesheet" {}
link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500;600;700&&display=block" rel="stylesheet" {}

link rel="stylesheet" href="https://kit.fontawesome.com/d4a1ffb2a0.css" crossorigin="anonymous";

meta name="viewport" content="width=device-width, initial-scale=1";

link rel="apple-touch-icon" sizes="180x180" href="/static/icons/apple-touch-icon.png";
link rel="icon" type="image/png" sizes="32x32" href="/static/icons/favicon-32x32.png";
link rel="icon" type="image/png" sizes="16x16" href="/static/icons/favicon-16x16.png";
link rel="manifest" href="/static/icons/site.webmanifest";
link rel="mask-icon" href="/static/icons/safari-pinned-tab.svg" color="#401f74";
link rel="shortcut icon" href="/static/icons/favicon.ico";
meta name="msapplication-TileColor" content="#603cba";
meta name="msapplication-config" content="/static/icons/browserconfig.xml";
meta name="theme-color" content="#401f74";


(og.borrow())

script type="text/javascript" {
Expand Down Expand Up @@ -98,13 +109,13 @@ pub fn header() -> Markup {
div class="flex flex-grow justify-center" {
div class="max-w-sm min-w-[200px] py-8 lg:py-12 flex-grow" {
a href="/" {
(PreEscaped(LOGO_SVG))
(PreEscaped(LOGO_DARK_FLAT_SVG))
}
}
}

nav class="flex flex-grow w-full pb-4 sm:pb-8" {
ul class="flex flex-col sm:flex-row justify-center sm:items-center flex-grow space-y-4 sm:space-y-0" {
ul class="text-lg flex flex-col sm:flex-row justify-center sm:items-center flex-grow space-y-4 sm:space-y-0" {
(HeaderLink { href: "/", text: "Home" })
(HeaderLink { href: "/posts", text: "Posts" })
(HeaderLink { href: "/til", text: "TILs" })
Expand Down
6 changes: 4 additions & 2 deletions server/src/http_server/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ mod footer;

pub use footer::footer;

const LOGO_SVG: &str = include_str!("../../../static/logo.svg");
const LOGO_MONOCHROME_SVG: &str = include_str!("../../../static/logo-monochrome.svg");
const LOGO_FLAT_SVG: &str = include_str!("../../../static/logo-flat.svg");
const LOGO_DARK_SVG: &str = include_str!("../../../static/logo-dark.svg");
const LOGO_DARK_FLAT_SVG: &str = include_str!("../../../static/logo-dark-flat.svg");

const MAX_WIDTH_CONTAINER_CLASSES: &str = "max-w-5xl m-auto px-4";

Expand All @@ -30,6 +31,7 @@ pub fn base(inner: impl Borrow<Markup>, og: header::OpenGraph) -> Markup {
body class="
bg-background
text-text
font-medium
font-sans
min-h-screen
flex
Expand Down
Binary file removed server/static/header_background.png
Binary file not shown.
Binary file added server/static/headshot-bg-removed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/headshot-bg-removed.webp
Binary file not shown.
Binary file added server/static/headshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions server/static/icons/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/static/mstile-150x150.png"/>
<TileColor>#603cba</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added server/static/icons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/favicon.ico
Binary file not shown.
Binary file added server/static/icons/mstile-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/mstile-310x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/mstile-310x310.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/static/icons/mstile-70x70.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions server/static/icons/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 48eac6a

Please sign in to comment.