Move feed fetching to crawl_feed job, DomainRequestLimiter
`DomainRequestLimiter` is a distributed version of `DomainLocks` based on redis.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use apalis::prelude::*;
|
||||
use apalis_redis::RedisStorage;
|
||||
use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::PgPool;
|
||||
use thiserror::Error;
|
||||
use tracing::{error, info, instrument};
|
||||
|
||||
@@ -8,6 +9,8 @@ mod crawl_feed;
|
||||
|
||||
pub use crawl_feed::CrawlFeedJob;
|
||||
|
||||
use crate::domain_request_limiter::DomainRequestLimiter;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub enum AsyncJob {
|
||||
HelloWorld(String),
|
||||
@@ -27,13 +30,18 @@ pub async fn handle_async_job(
|
||||
// TODO: add task_id to tracing instrumentation context
|
||||
// it casuses a panic in 0.6.0 currently, see: https://github.com/geofmureithi/apalis/issues/398
|
||||
// task_id: Data<TaskId>,
|
||||
http_client: Data<Client>,
|
||||
db: Data<PgPool>,
|
||||
domain_request_limiter: Data<DomainRequestLimiter>,
|
||||
) -> Result<(), AsyncJobError> {
|
||||
let result = match job {
|
||||
AsyncJob::HelloWorld(name) => {
|
||||
info!("Hello, {}!", name);
|
||||
Ok(())
|
||||
}
|
||||
AsyncJob::CrawlFeed(job) => crawl_feed::crawl_feed(job).await,
|
||||
AsyncJob::CrawlFeed(job) => {
|
||||
crawl_feed::crawl_feed(job, http_client, db, domain_request_limiter).await
|
||||
}
|
||||
};
|
||||
|
||||
match result {
|
||||
|
||||
Reference in New Issue
Block a user