mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
bring back intermediate job fetching
This commit is contained in:
@@ -65,17 +65,57 @@ async fn inbox_loop(ctx: Context, inbox_handlers: ImapConnectionHandlers) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// track number of continously executed jobs
|
||||||
|
let mut jobs_loaded = 0;
|
||||||
loop {
|
loop {
|
||||||
let probe_network = ctx.scheduler.read().await.get_probe_network();
|
let probe_network = ctx.scheduler.read().await.get_probe_network();
|
||||||
match job::load_next(&ctx, Thread::Imap, probe_network)
|
match job::load_next(&ctx, Thread::Imap, probe_network)
|
||||||
.timeout(Duration::from_millis(200))
|
.timeout(Duration::from_millis(200))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(Some(job)) => {
|
Ok(Some(job)) if jobs_loaded <= 20 => {
|
||||||
|
jobs_loaded += 1;
|
||||||
job::perform_job(&ctx, job::Connection::Inbox(&mut connection), job).await;
|
job::perform_job(&ctx, job::Connection::Inbox(&mut connection), job).await;
|
||||||
ctx.scheduler.write().await.set_probe_network(false);
|
ctx.scheduler.write().await.set_probe_network(false);
|
||||||
}
|
}
|
||||||
|
Ok(Some(job)) => {
|
||||||
|
// Let the fetch run, but return back to the job afterwards.
|
||||||
|
info!(ctx, "postponing imap-job {} to run fetch...", job);
|
||||||
|
jobs_loaded = 0;
|
||||||
|
fetch(&ctx, &mut connection).await;
|
||||||
|
}
|
||||||
Ok(None) | Err(async_std::future::TimeoutError { .. }) => {
|
Ok(None) | Err(async_std::future::TimeoutError { .. }) => {
|
||||||
|
jobs_loaded = 0;
|
||||||
|
fetch_idle(&ctx, &mut connection).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
info!(ctx, "Shutting down inbox loop");
|
||||||
|
fut.race(stop_receiver.recv().map(|_| ())).await;
|
||||||
|
shutdown_sender.send(()).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch(ctx: &Context, connection: &mut Imap) {
|
||||||
|
match get_watch_folder(&ctx, "configured_inbox_folder").await {
|
||||||
|
Some(watch_folder) => {
|
||||||
|
// fetch
|
||||||
|
connection
|
||||||
|
.fetch(&ctx, &watch_folder)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
error!(ctx, "{}", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
warn!(ctx, "Can not fetch inbox folder, not set");
|
||||||
|
connection.fake_idle(&ctx, None).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_idle(ctx: &Context, connection: &mut Imap) {
|
||||||
match get_watch_folder(&ctx, "configured_inbox_folder").await {
|
match get_watch_folder(&ctx, "configured_inbox_folder").await {
|
||||||
Some(watch_folder) => {
|
Some(watch_folder) => {
|
||||||
// fetch
|
// fetch
|
||||||
@@ -103,14 +143,6 @@ async fn inbox_loop(ctx: Context, inbox_handlers: ImapConnectionHandlers) {
|
|||||||
connection.fake_idle(&ctx, None).await;
|
connection.fake_idle(&ctx, None).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
info!(ctx, "Shutting down inbox loop");
|
|
||||||
fut.race(stop_receiver.recv().map(|_| ())).await;
|
|
||||||
shutdown_sender.send(()).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn simple_imap_loop(
|
async fn simple_imap_loop(
|
||||||
|
|||||||
Reference in New Issue
Block a user