Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indexes to good_jobs.finished_at and have GoodJob.cleanup_preserved_jobs delete all executions for a given job #477

Merged
merged 1 commit into from
Jan 3, 2022

Conversation

bensheldon
Copy link
Owner

Closes #476

@bensheldon bensheldon added the enhancement New feature or request label Jan 3, 2022
@bensheldon bensheldon temporarily deployed to goodjob-index-finished--fkwioz January 3, 2022 05:40 Inactive
@bensheldon bensheldon temporarily deployed to goodjob-index-finished--fkwioz January 3, 2022 05:45 Inactive
…erved_jobs` delete all executions for a given job
@bensheldon bensheldon temporarily deployed to goodjob-index-finished--fkwioz January 3, 2022 05:51 Inactive
@bensheldon bensheldon merged commit 3e02ab4 into main Jan 3, 2022
@bensheldon bensheldon deleted the index_finished_at branch January 3, 2022 16:20
@6temes
Copy link

6temes commented Jan 23, 2022

Hi @bensheldon

I just realized that, after running the latest migrations, I have two indices:

    t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at"
    t.index ["active_job_id"], name: "index_good_jobs_on_active_job_id"

I may be wrong, but wouldn't index_good_jobs_on_active_job_id be redundant? If I understand well, index_good_jobs_on_active_job_id_and_created_at is already indexing the active_job_id and, having both indices would only slow down writes.

@bensheldon
Copy link
Owner Author

@6temes you're right, those are redundant, and the singular/non-composite index could be dropped.

@nsilva-ta
Copy link

Hi @bensheldon

Why do we have an array with only one symbol for the column name?

    add_index :good_jobs, [:finished_at], where: "retried_good_job_id IS NULL AND finished_at IS NOT NULL", name: :index_good_jobs_jobs_on_finished_at

@reczy
Copy link
Contributor

reczy commented Apr 13, 2022

Hi @nsilva-ta,

Both ways of writing in the column_name are acceptable (symbol or array of symbols) - see here.

In fact, if you look at your schema after the migration, you'll see that they're all represented in array format:

    t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at"
    t.index ["active_job_id"], name: "index_good_jobs_on_active_job_id"
    t.index ["concurrency_key"], name: "index_good_jobs_on_concurrency_key_when_unfinished", where: "(finished_at IS NULL)"
    t.index ["cron_key", "created_at"], name: "index_good_jobs_on_cron_key_and_created_at"
    t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at", unique: true
    t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))"
    t.index ["queue_name", "scheduled_at"], name: "index_good_jobs_on_queue_name_and_scheduled_at", where: "(finished_at IS NULL)"
    t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

finished_at should be indexed and clean up should clean up all of a job's executions
4 participants