Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Add indexes, drop redundant column #7

Merged
merged 1 commit into from
Dec 14, 2023
Merged

Add indexes, drop redundant column #7

merged 1 commit into from
Dec 14, 2023

Conversation

bretthoerner
Copy link
Contributor

No description provided.

Comment on lines 1 to 3
-- Redundant with finished_at
ALTER TABLE
job_queue DROP COLUMN completed_at;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit(naming): Should we keep completed_at and drop finished_at? Any thoughts into which name fits better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of indifferent, but wondering if there's any reason to prefer one over the other.

Copy link
Contributor Author

@bretthoerner bretthoerner Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's currently used, finished_at feels slightly more correct. Because we set it even when we put a row back in for a retry:

impl<'c, J> PgTransactionJob<'c, J> {
pub async fn retry<E: serde::Serialize + std::marker::Sync>(
mut self,
error: E,
preferred_retry_interval: Option<time::Duration>,
) -> Result<RetryableJob<E>, PgJobError<PgTransactionJob<'c, J>>> {
if self.job.is_gte_max_attempts() {
return Err(PgJobError::RetryInvalidError {
job: self,
error: "Maximum attempts reached".to_owned(),
});
}
let retryable_job = self.job.retry(error);
let retry_interval = self
.retry_policy
.time_until_next_retry(&retryable_job, preferred_retry_interval);
let base_query = format!(
r#"
UPDATE
"{0}"
SET
finished_at = NOW(),
status = 'available'::job_status,
scheduled_at = NOW() + $3,
errors = array_append("{0}".errors, $4)
WHERE
"{0}".id = $2
AND queue = $1
RETURNING
"{0}".*

To me, completed really means we're done (completed or failed) where it seems like we're using finished_at as more like a last_attempt_finished_at (maybe that over verbose name would be better?)

edit: I don't know why I feel like completed is more "final" than finished. Although IMO it would be odd to use completed_at AND have the completed status, and have rows with completed_at not NULL and status = available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree completed_at feels more final and implies it was with completed status. We could have one timestamp per status, i.e. completed_at, failed_at, retried_at, but that gets redundant quickly and hard to maintain if we ever add another status.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be an array, only the final timestamp could be completed or failed anyway, anything before the final basically has to be "attempt that failed". I guess all that gets us is knowledge of when failed attempts happened, I don't know how useful that is. You're right that we could add more statuses anyway, though.

Copy link
Contributor

@tomasfarias tomasfarias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would squash migrations given that this is not yet released anywhere (I personally drop and recreate my local Postgres all the time). Not a blocker though as we can squash before moving this to production.

scheduled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
status job_status NOT NULL DEFAULT 'available'::job_status,
status job_status NOT NULL DEFAULT 'available' :: job_status,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ew, I use the vscode SQL Formatter extension and disagree with its choices, one sec.

@bretthoerner bretthoerner merged commit 2b03197 into main Dec 14, 2023
4 checks passed
@bretthoerner bretthoerner deleted the brett/indexes branch January 17, 2024 15:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants