mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
Merge pull request #766 from actix/dependabot/cargo/chrono-0.4.35
chore(deps): bump chrono from 0.4.34 to 0.4.35
This commit is contained in:
commit
9a7d5bbb5f
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -2016,9 +2016,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.34"
|
version = "0.4.35"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
|
checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#![allow(clippy::extra_unused_lifetimes)]
|
#![allow(clippy::extra_unused_lifetimes)]
|
||||||
|
|
||||||
|
use chrono::{NaiveDateTime, TimeDelta, Utc};
|
||||||
use diesel::{r2d2::ConnectionManager, PgConnection};
|
use diesel::{r2d2::ConnectionManager, PgConnection};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::schema::*;
|
use super::schema::*;
|
||||||
|
|
||||||
@ -13,7 +15,7 @@ pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
|
|||||||
pub struct User {
|
pub struct User {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub hash: String,
|
pub hash: String,
|
||||||
pub created_at: chrono::NaiveDateTime,
|
pub created_at: NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
@ -29,9 +31,9 @@ impl User {
|
|||||||
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
|
#[derive(Debug, Serialize, Deserialize, Queryable, Insertable)]
|
||||||
#[diesel(table_name = invitations)]
|
#[diesel(table_name = invitations)]
|
||||||
pub struct Invitation {
|
pub struct Invitation {
|
||||||
pub id: uuid::Uuid,
|
pub id: Uuid,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub expires_at: chrono::NaiveDateTime,
|
pub expires_at: NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
// any type that implements Into<String> can be used to create Invitation
|
// any type that implements Into<String> can be used to create Invitation
|
||||||
@ -41,9 +43,9 @@ where
|
|||||||
{
|
{
|
||||||
fn from(email: T) -> Self {
|
fn from(email: T) -> Self {
|
||||||
Invitation {
|
Invitation {
|
||||||
id: uuid::Uuid::new_v4(),
|
id: Uuid::new_v4(),
|
||||||
email: email.into(),
|
email: email.into(),
|
||||||
expires_at: chrono::Local::now().naive_local() + chrono::Duration::hours(24),
|
expires_at: (Utc::now() + TimeDelta::try_hours(24).unwrap()).naive_utc(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use actix_web::{
|
|||||||
HttpResponse, Responder,
|
HttpResponse, Responder,
|
||||||
};
|
};
|
||||||
use apalis::{prelude::*, redis::RedisStorage};
|
use apalis::{prelude::*, redis::RedisStorage};
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{TimeDelta, Utc};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{persistent_jobs::Email, ItemCache};
|
use crate::{persistent_jobs::Email, ItemCache};
|
||||||
@ -12,7 +12,7 @@ use crate::{persistent_jobs::Email, ItemCache};
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub(crate) struct CacheInsert {
|
pub(crate) struct CacheInsert {
|
||||||
data: String,
|
data: String,
|
||||||
duration: u64,
|
duration: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/cache")]
|
#[get("/cache")]
|
||||||
@ -26,7 +26,7 @@ pub(crate) async fn cache_item(
|
|||||||
cache: Data<ItemCache>,
|
cache: Data<ItemCache>,
|
||||||
web::Json(form): web::Json<CacheInsert>,
|
web::Json(form): web::Json<CacheInsert>,
|
||||||
) -> actix_web::Result<impl Responder> {
|
) -> actix_web::Result<impl Responder> {
|
||||||
let expires = Utc::now() + Duration::seconds(form.duration as i64);
|
let expires = Utc::now() + TimeDelta::try_seconds(form.duration as i64).unwrap();
|
||||||
|
|
||||||
// insert into item cache
|
// insert into item cache
|
||||||
cache.lock().unwrap().insert(form.data, expires);
|
cache.lock().unwrap().insert(form.data, expires);
|
||||||
|
@ -11,8 +11,8 @@ use actix_web::{
|
|||||||
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
|
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
|
||||||
Error, HttpResponse,
|
Error, HttpResponse,
|
||||||
};
|
};
|
||||||
use chrono::{Local, NaiveDateTime};
|
use chrono::{DateTime, Utc};
|
||||||
use futures_util::{future::LocalBoxFuture, FutureExt, TryFutureExt};
|
use futures_util::{future::LocalBoxFuture, FutureExt as _, TryFutureExt as _};
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct RateLimitService<S> {
|
pub struct RateLimitService<S> {
|
||||||
@ -95,7 +95,7 @@ struct TokenBucket {
|
|||||||
capacity: u64,
|
capacity: u64,
|
||||||
|
|
||||||
/// Time that last request was accepted.
|
/// Time that last request was accepted.
|
||||||
last_req_time: NaiveDateTime,
|
last_req_time: DateTime<Utc>,
|
||||||
|
|
||||||
/// Numbers of tokens remaining.
|
/// Numbers of tokens remaining.
|
||||||
///
|
///
|
||||||
@ -108,7 +108,7 @@ impl TokenBucket {
|
|||||||
fn new(limit: u64) -> Self {
|
fn new(limit: u64) -> Self {
|
||||||
TokenBucket {
|
TokenBucket {
|
||||||
limit,
|
limit,
|
||||||
last_req_time: NaiveDateTime::UNIX_EPOCH,
|
last_req_time: DateTime::<Utc>::UNIX_EPOCH,
|
||||||
capacity: limit,
|
capacity: limit,
|
||||||
tokens: 0,
|
tokens: 0,
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ impl TokenBucket {
|
|||||||
|
|
||||||
/// Mutates leaky bucket for accepted request.
|
/// Mutates leaky bucket for accepted request.
|
||||||
fn allow_query(&mut self) -> bool {
|
fn allow_query(&mut self) -> bool {
|
||||||
let current_time = Local::now().naive_local();
|
let current_time = Utc::now();
|
||||||
|
|
||||||
let time_elapsed = (current_time.timestamp() - self.last_req_time.timestamp()) as u64;
|
let time_elapsed = (current_time.timestamp() - self.last_req_time.timestamp()) as u64;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user