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 worker queue #630

Merged
merged 1 commit into from
Nov 30, 2023
Merged

Add worker queue #630

merged 1 commit into from
Nov 30, 2023

Conversation

slifty
Copy link
Member

@slifty slifty commented Nov 27, 2023

This PR adds support to the PDC for a worker queue and creates a "shell" worker for bulk upload processing (the worker doesn't actually do anything yet).

This builds on the work of #628 and shouldn't be reviewed until that has been merged and this PR has been rebased.

Related to #559

@slifty
Copy link
Member Author

slifty commented Nov 27, 2023

It's unclear to me why tests are failing in CI -- they are passing locally.

Update: pretty sure the issue is that the tests themselves don't trigger migrations for the job queue (whereas in my case the migrations had already been run).

Second Update: yep! I'm opting to just mock the queue library to avoid any interaction with the worker queue in our tests.

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (8f82c68) 94.77% compared to head (00bc5ce) 92.92%.

Files Patch % Lines
src/jobQueue.ts 45.45% 18 Missing ⚠️
src/index.ts 0.00% 3 Missing ⚠️
src/errors/JobQueueStateError.ts 0.00% 1 Missing ⚠️
src/handlers/bulkUploadsHandlers.ts 75.00% 1 Missing ⚠️
src/tasks/processBulkUpload.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #630      +/-   ##
==========================================
- Coverage   94.77%   92.92%   -1.86%     
==========================================
  Files          74       80       +6     
  Lines        1071     1130      +59     
  Branches      169      180      +11     
==========================================
+ Hits         1015     1050      +35     
- Misses         51       75      +24     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jasonaowen jasonaowen left a comment

Choose a reason for hiding this comment

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

I haven't tested this yet; just a quick review!

Also @slifty would you mind talking through how you decided on graphile-worker? I'm 100% on board with that choice, just curious to hear your reasoning!

src/index.ts Outdated Show resolved Hide resolved
src/jobQueue.ts Outdated Show resolved Hide resolved
src/tasks/processBulkUpload.ts Outdated Show resolved Hide resolved
@slifty slifty force-pushed the 559-add-worker-queue branch 2 times, most recently from 4a60962 to e014f49 Compare November 28, 2023 16:43
Copy link
Contributor

@jasonaowen jasonaowen left a comment

Choose a reason for hiding this comment

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

As you called out in the description, this needs to be rebased on main now that #628 is merged.

I was able to run this locally, and both see successful jobs by using the new bulk upload API endpoint, and failed jobs by using the SQL interface to add a job without a payload.

I think we want to configure logging as part of this, but otherwise this is looking great!

src/jobQueue.ts Outdated Show resolved Hide resolved
src/tasks/processBulkUpload.ts Show resolved Hide resolved
src/jobQueue.ts Show resolved Hide resolved
src/tasks/processBulkUpload.ts Outdated Show resolved Hide resolved
@slifty slifty force-pushed the 559-add-worker-queue branch 3 times, most recently from b58a76d to 6886b2d Compare November 29, 2023 22:29
Copy link
Contributor

@jasonaowen jasonaowen left a comment

Choose a reason for hiding this comment

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

This looks good to me! I was able to run this locally again, now with prettier logs. The common database connection pool seems to be working well, and I was able to drop the database schema (drop schema graphile_worker cascade;) and recreate via npm run migrate:dev.

Need to fix the failing test, but that should be pretty minor, so +1! Nice work, @slifty.

src/tasks/__tests__/processBulkUpload.unit.test.ts Outdated Show resolved Hide resolved
@slifty slifty force-pushed the 559-add-worker-queue branch 2 times, most recently from f8b68ee to efea25d Compare November 30, 2023 16:28
import { jobQueueLogger } from '../jobQueue';
import type { JobHelpers } from 'graphile-worker';

export const getMockJobHelpers = (): JobHelpers => ({
Copy link
Member Author

@slifty slifty Nov 30, 2023

Choose a reason for hiding this comment

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

@jasonaowen this is what I did for mocking job helpers -- we only use the logger helper, and since this is JUST for test code I think it's OK to be a little more "fast and loose" / not try to mock all the other things that JobHelpers can do. Worst case a future test fails and we expand the mock at that point.

We want to process bulk uploads asynchronously, and so this means we
need a worker queue.  Since this initial task is going to be infrequent,
we felt it did not warrant adding a new dependency to our stack (e.g.
reddis or rabbitmq), and so we're going to just leverage postgres as our
backend.

I explored two tools for this purpose: pg-boss, and graphile-worker.
Both packages appeared to meet our technical needs, and both seem to be
maintained and similarly popular.  I decided to go with graphile-worker
as it appears to be part of a suite of related tools and the primary
developer appears to have built a community around that suite of tools
(and earns some income to support the development of the project).

Issue #559 Set up a queue / processing system for handling bulk proposal uploads
@slifty
Copy link
Member Author

slifty commented Nov 30, 2023

I'll merge this after CI completes (I did add that mockGraphileWorker.ts file but am leaning into post-merge fixes if there are concerns there.

@slifty slifty merged commit f800538 into main Nov 30, 2023
2 of 4 checks passed
@slifty slifty deleted the 559-add-worker-queue branch November 30, 2023 16:36
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.

2 participants