-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webserver): implement doc crawler job (#2431)
* feat(webserver): implement doc crawler job * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3ef1bc4
commit b485d12
Showing
6 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ee/tabby-webserver/src/service/background_job/web_crawler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::sync::Arc; | ||
|
||
use chrono::{DateTime, Utc}; | ||
use tabby_inference::Embedding; | ||
use tabby_schema::{web_crawler::WebCrawlerService, Result}; | ||
use tokio::sync::mpsc::UnboundedSender; | ||
|
||
use super::{helper::Job, BackgroundJobEvent}; | ||
|
||
pub struct WebCrawlerJob { | ||
url: String, | ||
} | ||
|
||
impl Job for WebCrawlerJob { | ||
const NAME: &'static str = "web_crawler"; | ||
} | ||
|
||
impl WebCrawlerJob { | ||
pub fn new(url: String) -> Self { | ||
Self { url } | ||
} | ||
|
||
pub async fn run(self, embedding: Arc<dyn Embedding>) { | ||
tabby_scheduler::crawl_index_docs(&[self.url], embedding).await; | ||
} | ||
|
||
pub async fn cron( | ||
_now: DateTime<Utc>, | ||
sender: UnboundedSender<BackgroundJobEvent>, | ||
web_crawler_service: Arc<dyn WebCrawlerService>, | ||
) -> Result<()> { | ||
for url in web_crawler_service | ||
.list_web_crawler_urls(None, None, None, None) | ||
.await? | ||
{ | ||
sender | ||
.send(BackgroundJobEvent::WebCrawler(url.url)) | ||
.expect("Failed to enqueue web crawler job"); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters