Conversation
ChuckHend
commented
Feb 26, 2024
Comment on lines
+47
to
+70
| let mut ext_ready: bool = false; | ||
| let mut wait_duration: Duration = Duration::from_secs(6); | ||
| while BackgroundWorker::wait_latch(Some(wait_duration)) { | ||
| if !ext_ready { | ||
| warning!("pg-vectorize: waiting for CREATE EXTENSION vectorize CASCADE;"); | ||
| runtime.block_on(async { | ||
| ext_ready = ready(&conn).await; | ||
| }); | ||
| // return to wait_latch if extension is not ready | ||
| continue; | ||
| } | ||
|
|
||
| let _worker_ran: Result<()> = runtime.block_on(async { | ||
| // continue to poll without pauses | ||
| let start = Instant::now(); | ||
| let duration = Duration::from_secs(6); | ||
| // return control to wait_latch() after `duration` has elapsed | ||
| while start.elapsed() < duration { | ||
| match run_worker(queue.clone(), &conn, VECTORIZE_QUEUE).await { | ||
| // sleep for 2 seconds when no messages in the queue | ||
| Ok(None) => tokio::time::sleep(Duration::from_secs(2)).await, | ||
| // sleep for 6 seconds when there is an error reading messages | ||
| Err(_) => tokio::time::sleep(Duration::from_secs(6)).await, | ||
| // continue to poll where there was a message consumed | ||
| Ok(Some(_)) => continue, | ||
| } | ||
| } | ||
| Ok(()) | ||
| wait_duration = runtime.block_on(async { | ||
| let wait_dur = match run_worker(queue.clone(), &conn, VECTORIZE_QUEUE).await { | ||
| // no messages in queue, so wait 2 seconds | ||
| Ok(None) => 2000, | ||
| // wait 10 seconds between polls when there is a failure | ||
| Err(_) => 10000, | ||
| // when there was a successfully processed message from queue, | ||
| // only wait 10ms before checking for more messages | ||
| // this allows postgres to kill or restart the bgw in between messages | ||
| Ok(Some(_)) => 10, | ||
| }; | ||
| Duration::from_millis(wait_dur) |
nhudson
approved these changes
Feb 26, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.