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

Create "discrete" good_job_executions table to separate Job records from Execution records and have a 1-to-1 correspondence between good_jobs records and Active Job jobs #928

Merged
merged 9 commits into from
Apr 22, 2023

Conversation

bensheldon
Copy link
Owner

@bensheldon bensheldon commented Apr 14, 2023

On the path to #831, which requires having a single row per job to lock, whereas currently GoodJob overloads a single table to contain both Execution and Job records, which leads to multiple rows with the same active_job_id.

This PR provides a backwards-compatible/minor-releasable change by adding a new good_job_executions table corresponding to GoodJob::DiscreteExecutions model, along with a boolean is_discrete column on Jobs/Executions. Once the migration is run, subsequently created jobs will be discrete, and they will use the new table. Old, non-discrete jobs will continue to run with multiple executions.

discrete Job records are updated in place with the most recent attributes after retries. DiscreteExecutions/good_job_executions are used to track historical changes in job attributes (#271)

Because is_discrete is a nice boolean for adding in additional behavior, a few other minor changes:

  • Discrete Jobs' id is the same as the active_job_id. This is a nice alignment with Active Job.
  • Discrete Jobs' all should have a scheduled_at value. If it is not actually scheduled for the future, it should be identical to the created_at value. This should help make the fetch-and-lock query a little simpler while still being able to differentiate between jobs that are intended to run immediately or are actually scheduled.

When this gets to the v3.99 release, it will be necessary to ensure that all unfinished jobs are discrete so that v4.0 can safely remove the backwards compatible code-paths. I'm imagining some kind of "Healthcheck" to peep that out, but that's not implemented here.

  • Update Dashboard to show the Job's serialized_params, which is necessary because DiscreteExecutions are not created until the job is performed, which is different currently than Executions.

@bensheldon
Copy link
Owner Author

Benchmarking this seems very inconsequential, despite the additional transactions and inserts:

 ruby scripts/benchmark_discrete_jobs.rb
To use retry middleware with Faraday v2.0+, install `faraday-retry` gem
Warming up --------------------------------------
discrete jobs and no errors
                         4.000  i/100ms
undiscrete jobs and no errors
                         4.000  i/100ms
discrete jobs and 5 errors
                         4.000  i/100ms
undiscrete jobs and 5 errors
                         4.000  i/100ms
Calculating -------------------------------------
discrete jobs and no errors
                         47.279  (± 6.3%) i/s -    236.000  in   5.007317s
undiscrete jobs and no errors
                         47.613  (± 4.2%) i/s -    240.000  in   5.052548s
discrete jobs and 5 errors
                         48.203  (±12.4%) i/s -    240.000  in   5.044026s
undiscrete jobs and 5 errors
                         45.840  (± 6.5%) i/s -    232.000  in   5.080429s

Comparison:
discrete jobs and 5 errors:       48.2 i/s
undiscrete jobs and no errors:       47.6 i/s - same-ish: difference falls within error
discrete jobs and no errors:       47.3 i/s - same-ish: difference falls within error
undiscrete jobs and 5 errors:       45.8 i/s - same-ish: difference falls within error

@bensheldon bensheldon changed the title Create "discrete" good_job_executions table to separate Job records from Execution records Create "discrete" good_job_executions table to separate Job records from Execution records and have a 1-to-1 correspondence between good_jobs records and Active Job jobs Apr 20, 2023
@bensheldon bensheldon marked this pull request as ready for review April 22, 2023 02:30
@bensheldon bensheldon merged commit e5fbe91 into main Apr 22, 2023
@bensheldon bensheldon deleted the discrete_executions branch April 22, 2023 02:31
grncdr added a commit to grncdr/good_job that referenced this pull request Jan 3, 2024
This variable is a GoodJob::DiscreteExecution except in cases where
migrations have not been run in a long time. That case didn't seem
worthy of cluttering up the comment.

See: bensheldon#928
bensheldon added a commit that referenced this pull request Feb 22, 2024
* Add extension partials to good_job/jobs#show view

* Install empty extension partials in good_job:install

* Update README section about extending dashboard views

* Fix lint error

* Add view extension example and system spec

* Correct class name in default custom partial

This variable is a GoodJob::DiscreteExecution except in cases where
migrations have not been run in a long time. That case didn't seem
worthy of cluttering up the comment.

See: #928

* Remove generators and move partials to `app/views/good_job`

* Add system test and move demo partials to proper place

---------

Co-authored-by: Ben Sheldon [he/him] <bensheldon@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

1 participant