Skip to content

Add addJobWithClient and addJobsWithClient to WorkerUtils - #667

Open
Olayanju-1234 wants to merge 1 commit into
graphile:mainfrom
Olayanju-1234:feat/add-job-with-client
Open

Olayanju-1234 wants to merge 1 commit into
graphile:mainfrom
Olayanju-1234:feat/add-job-with-client

Conversation

@Olayanju-1234

Copy link
Copy Markdown

Description

Closes #538.

Adds two methods to WorkerUtils:

  • addJobWithClient(client, identifier, payload, spec)
  • addJobsWithClient(client, jobSpecs, jobKeyPreserveRunAt) (experimental, like addJobs)

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 WorkerUtils so migrate() and the rest still work.

Both reuse makeAddJob / makeAddJobs with makeWithPgClientFromClient, so the SQL, useNodeTime and the typed payloads are the same as addJob / addJobs. client is typed as PoolClient, like withPgClient and runTaskListOnce. The docs get a short "Adding jobs in your own transaction" section under WorkerUtils.

I added addJobsWithClient so the batch API has the same option. Happy to drop it if you'd rather keep this to addJob.

Performance impact

None for existing code. The new methods run the same add_job / add_jobs SQL 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

  • My code matches the project's code style and yarn lint:fix passes.
  • I've added tests for the new feature, and yarn test passes.
  • I have detailed the new feature in the relevant documentation.
  • I have added this feature to 'Pending' in the RELEASE_NOTES.md file (if one exists). There is no RELEASE_NOTES.md, so I added a changeset (patch).
  • If this is a breaking change I've explained why. (Not a breaking change.)

The new tests in workerUtils.addJob.test.ts and workerUtils.addJobs.test.ts add 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 on main with addJobWithClient is not a function and pass here. Locally yarn test passes apart from 3 timing assertions in main.runTaskListOnce.test.ts that also fail on main in my setup: run_at comes back 1 ms before the test's start time because my Postgres runs in Docker with a slightly different clock.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a specific client for addGraphileJobs library function.

1 participant