-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cyclotron): Change dead-letter strategy, adopt in fetch and jani…
…tor (#24569) Co-authored-by: Brett Hoerner <[email protected]>
- Loading branch information
1 parent
e9e3441
commit 615c435
Showing
17 changed files
with
406 additions
and
209 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
rust/.sqlx/query-2bd3251126625d8dd5143f58f4f9c4bbd0c3a17b7ea65767cf5e7512e5a6ea89.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
rust/.sqlx/query-2ca9ea5e8706bba21b14d9a349f3d0e39f01b19b243d724b09f3ce6617d03dc7.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
rust/.sqlx/query-385e94f4adab0f85174968f6eee873bf6d1d43884cd628df5b36978dd761b025.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
rust/.sqlx/query-78f54fcebc11e2411008448281e4711bdfb8cf78e362ccda8bc14e92324d51f8.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
rust/.sqlx/query-b8c1b723826d595dca0389d729fa76bd8a7d96d73983a0c408f32f17da5f483b.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
rust/.sqlx/query-fdda5a80f5495f2d4b15ce1a0963f990986c8b8433f01e449fbd1eee70ce6aeb.json
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use crate::DEAD_LETTER_QUEUE; | ||
use chrono::Duration; | ||
use sqlx::PgPool; | ||
|
||
use crate::{ | ||
ops::{ | ||
janitor::{ | ||
delete_completed_jobs, delete_failed_jobs, detect_poison_pills, reset_stalled_jobs, | ||
}, | ||
meta::{count_total_waiting_jobs, dead_letter, run_migrations}, | ||
}, | ||
PoolConfig, QueueError, | ||
}; | ||
|
||
// Thin layer on top of the raw janitor operations - mostly just avoids users having to take a dep on sqlx | ||
pub struct Janitor { | ||
pub pool: PgPool, | ||
} | ||
|
||
impl Janitor { | ||
pub async fn new(config: PoolConfig) -> Result<Self, QueueError> { | ||
let pool = config.connect().await?; | ||
Ok(Self { pool }) | ||
} | ||
|
||
pub fn from_pool(pool: PgPool) -> Self { | ||
Self { pool } | ||
} | ||
|
||
pub async fn run_migrations(&self) { | ||
run_migrations(&self.pool).await; | ||
} | ||
|
||
pub async fn delete_completed_jobs(&self) -> Result<u64, QueueError> { | ||
delete_completed_jobs(&self.pool).await | ||
} | ||
|
||
pub async fn delete_failed_jobs(&self) -> Result<u64, QueueError> { | ||
delete_failed_jobs(&self.pool).await | ||
} | ||
|
||
pub async fn reset_stalled_jobs(&self, timeout: Duration) -> Result<u64, QueueError> { | ||
reset_stalled_jobs(&self.pool, timeout).await | ||
} | ||
|
||
pub async fn delete_poison_pills( | ||
&self, | ||
timeout: Duration, | ||
max_janitor_touched: i16, | ||
) -> Result<u64, QueueError> { | ||
let poison = detect_poison_pills(&self.pool, timeout, max_janitor_touched).await?; | ||
|
||
for job in &poison { | ||
dead_letter( | ||
&self.pool, | ||
*job, | ||
&format!("poison pill detected based on a timeout of {}", timeout), | ||
) | ||
.await?; | ||
} | ||
|
||
Ok(poison.len() as u64) | ||
} | ||
|
||
pub async fn waiting_jobs(&self) -> Result<u64, QueueError> { | ||
count_total_waiting_jobs(&self.pool).await | ||
} | ||
|
||
pub async fn count_dlq_depth(&self) -> Result<u64, QueueError> { | ||
let result = sqlx::query_scalar!( | ||
"SELECT COUNT(*) FROM cyclotron_jobs WHERE queue_name = $1", | ||
DEAD_LETTER_QUEUE | ||
) | ||
.fetch_one(&self.pool) | ||
.await | ||
.map_err(QueueError::from)?; | ||
|
||
Ok(result.unwrap_or(0) as u64) | ||
} | ||
} |
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
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
Oops, something went wrong.