Repository navigation
Add addJobWithClient and addJobsWithClient to WorkerUtils - #667
Open
Olayanju-1234 wants to merge 1 commit into
Open
Olayanju-1234 wants to merge 1 commit into
Olayanju-1234 wants to merge 1 commit into
Conversation
Adds jobs using a client the caller passes in, so they can be added inside the caller's own transaction and are only visible once it commits. Reuses makeAddJob and makeAddJobs with makeWithPgClientFromClient. Closes graphile#538.
This branch has not been deployed
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.
Description
Closes #538.
Adds two methods to
WorkerUtils:addJobWithClient(client, identifier, payload, spec)addJobsWithClient(client, jobSpecs, jobKeyPreserveRunAt)(experimental, likeaddJobs)They add jobs using the client you pass instead of one from the pool, so a job can be added inside your own transaction and only exists if that transaction commits. This is the shape you suggested in #538, on
WorkerUtilssomigrate()and the rest still work.Both reuse
makeAddJob/makeAddJobswithmakeWithPgClientFromClient, so the SQL,useNodeTimeand the typed payloads are the same asaddJob/addJobs.clientis typed asPoolClient, likewithPgClientandrunTaskListOnce. The docs get a short "Adding jobs in your own transaction" section underWorkerUtils.I added
addJobsWithClientso the batch API has the same option. Happy to drop it if you'd rather keep this toaddJob.Performance impact
None for existing code. The new methods run the same
add_job/add_jobsSQL on the caller's client.Security impact
None known. The SQL and its parameters are the same as
addJob/addJobs; only the connection changes.Checklist
yarn lint:fixpasses.yarn testpasses.RELEASE_NOTES.mdfile (if one exists). There is noRELEASE_NOTES.md, so I added a changeset (patch).The new tests in
workerUtils.addJob.test.tsandworkerUtils.addJobs.test.tsadd jobs on a client inside a transaction, check they are visible on that client but not from the pool, roll back (no jobs), then add again and commit (jobs visible from the pool). They fail onmainwithaddJobWithClient is not a functionand pass here. Locallyyarn testpasses apart from 3 timing assertions inmain.runTaskListOnce.test.tsthat also fail onmainin my setup:run_atcomes back 1 ms before the test's start time because my Postgres runs in Docker with a slightly different clock.