Skip to content

Commit

Permalink
Merge pull request #9 from MoveOnOrg/kathy-fix-504-bulk
Browse files Browse the repository at this point in the history
Add assignment load limit
  • Loading branch information
crayolakat authored Mar 8, 2024
2 parents b8b651f + f9d00b7 commit de558ff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
25 changes: 25 additions & 0 deletions __test__/server/api/assignment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,29 @@ describe("test getContacts timezone stuff only", () => {
/^select \* from .campaign_contact. where .assignment_id. = 1.*/
);
}); // it

it("returns the correct query -- assignment load limit not set", () => {
let query = getContacts(
assignment,
{ validTimezone: null },
organization,
campaign
);
expect(query.toString()).not.toMatch(
/^select \* from .campaign_contact. where .assignment_id. = 1.* limit 1/
);
}); // it

it("returns the correct query -- assignment load limit set", () => {
global["ASSIGNMENT_LOAD_LIMIT"] = 1;
let query = getContacts(
assignment,
{ validTimezone: null },
organization,
campaign
);
expect(query.toString()).toMatch(
/^select \* from .campaign_contact. where .assignment_id. = 1.* limit 1/
);
}); // it
}); // describe
1 change: 1 addition & 0 deletions dev-tools/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ PHONE_INVENTORY=1
ALLOW_SEND_ALL=false
DST_REFERENCE_TIMEZONE='America/New_York'
PASSPORT_STRATEGY=local
ASSIGNMENT_LOAD_LIMIT=1
1 change: 1 addition & 0 deletions docs/REFERENCE-environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
| ASSETS_DIR | Directory path where front-end packaged JavaScript is saved and loaded. _Required_. |
| ASSETS_MAP_FILE | File name of map file, within ASSETS_DIR, containing map of general file names to unique build-specific file names. |
| ASSIGNMENT_CONTACTS_SIDEBAR | Show a sidebar with a list of contacts to the texter. Allows texter to freely navigate between conversations, regardless of status. |
| ASSIGNMENT_LOAD_LIMIT | Limit of contacts to load at one time for an assignment. Used when Spoke is deployed on a service with time and bandwidth limitations, such as AWS Lambda. Type: integer |
| AUTH0_DOMAIN | Domain name on Auth0 account, should end in `.auth0.com`, e.g. `example.auth0.com`. _Required_. |
| AUTH0_CLIENT_ID | Client ID from Auth0 app. _Required_. |
| AUTH0_CLIENT_SECRET | Client secret from Auth0 app. _Required_. |
Expand Down
8 changes: 8 additions & 0 deletions src/server/api/assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export function getContacts(
query = query.where({
assignment_id: assignment.id
});

let assignmentLoadLimit = getConfig("ASSIGNMENT_LOAD_LIMIT");
if (assignmentLoadLimit) {
assignmentLoadLimit = parseInt(assignmentLoadLimit);
if (!isNaN(assignmentLoadLimit)) {
query.limit(assignmentLoadLimit);
}
}
}

if (contactsFilter) {
Expand Down

0 comments on commit de558ff

Please sign in to comment.